N,M = map(int, input().split()) S = input() E = [[] for _ in range(N)] for _ in range(M): u,v = map(int, input().split()) E[u-1].append(v-1) E[v-1].append(u-1) mod = 10**9+7 PDCA = [0]*N for i in range(N): if S[i] != "P": continue for v in E[i]: if S[v] == "D": PDCA[v] += 1 for i in range(N): if S[i] != "D": continue for v in E[i]: if S[v] == "C": PDCA[v] += PDCA[i] for i in range(N): if S[i] != "C": continue for v in E[i]: if S[v] == "A": PDCA[v] += PDCA[i] ans = 0 for i in range(N): if S[i] == "A": ans += PDCA[i] ans %= mod print(ans)