N,M = map(int,input().split()) S = input() from collections import defaultdict dic = defaultdict(list) from functools import lru_cache 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[v - 1].append(u - 1) if S[v - 1] + S[u - 1] in T: G[u - 1].append(v - 1) @lru_cache(maxsize=1000) def dfs(x): if S[x] == "P": return 1 res = 0 for child in G[x]: res += dfs(child) res %= DIV return res ans = 0 for v in dic["A"]: ans += dfs(v) ans %= DIV print(ans)