from functools import lru_cache MOD = 10 ** 9 + 7 N, M = map(int, input().split()) S = input() UV = [list(map(int, input().split())) for _ in range(M)] E = [[] for _ in range(N)] A = ["P", "D", "C", "A"] for u, v in UV: u -= 1 v -= 1 a = A.index(S[u]) if a < 3 and S[v] == A[a + 1]: E[u].append(v) if 0 < a and S[v] == A[a - 1]: E[v].append(u) @lru_cache(maxsize=1000) def dfs(x): if S[x] == "A": return 1 ret = 0 for v in E[x]: ret += dfs(v) return ret ans = 0 for i in range(N): if S[i] == "P": ans += dfs(i) ans %= MOD print(ans)