N,M = map(int,input().split()) S = input() from collections import defaultdict dic = defaultdict(list) for i in range(N): dic[S[i]].append(i) T = "PDCA" DIV = 1000000007 G = [[] for i in range(N)] for _ in range(M): u,v = map(int,input().split()) if S[u - 1] + S[v - 1] in T: G[u - 1].append(v - 1) if S[v - 1] + S[u - 1] in T: G[v - 1].append(u - 1) dp = [0] * N for v in dic["P"]: dp[v] = 1 for i in range(len(T) - 1): for v in dic[T[i]]: for child in G[v]: dp[child] += dp[v] dp[child] %= DIV ans = 0 for v in dic["A"]: ans += dp[v] ans %= DIV print(ans)