import sys sys.setrecursionlimit(10**6) v_count, edge_count = map(int, input().split()) S = input() edges = [[] for _ in [0]*v_count] next_c = {"P":"D", "D":"C", "C":"A", "A":""} mod = 10**9+7 for u, v in (map(int, l.split()) for l in sys.stdin): edges[u-1].append(v-1) edges[v-1].append(u-1) dp = [-1]*v_count def rec(v, c): if dp[v] == -1: _c = next_c[c] dp[v] = sum(rec(dest, _c)for dest in edges[v] if S[dest] == c) % mod return dp[v] a_index = S.find("A") while a_index != -1: dp[a_index] = 1 a_index = S.find("A", a_index+1) ans = 0 p_index = S.find("P") while p_index != -1: ans += rec(p_index, "D") p_index = S.find("P", p_index+1) print(ans % mod)