N, M = map(int, input().split()) S = input() edge_pd, edge_dc, edge_ca = [], [], [] dp = [0] * 101010 MOD = 1000000007 for _ in range(M): u, v = map(int, input().split()) u -= 1 v -= 1 if S[u] < S[v]: u, v = v, u ca = S[u] cb = S[v] if ca == "P" and cb == "D": edge_pd.append((u, v)) dp[u] = 1 elif ca == "D" and cb == "C": edge_dc.append((u, v)) elif ca == "C" and cb == "A": edge_ca.append((u, v)) for u, v in edge_pd: dp[v] = (dp[u] + dp[v]) % MOD for u, v in edge_dc: dp[v] = (dp[u] + dp[v]) % MOD ans = 0 for u, _ in edge_ca: ans = (ans + dp[u]) % MOD print(ans)