import sys import io, os sys.setrecursionlimit(10**9) input = sys.stdin.readline n, m = map(int, input().split()) s = str(input().rstrip()) g = [[] for i in range(n)] mod = 10**9+7 for i in range(m): u, v = map(int, input().split()) u, v = u-1, v-1 g[u].append(v) g[v].append(u) memo = {} def dfs(v, A): if len(A) == 4: return 1 if v in memo: return v ret = 0 for u in g[v]: if A[-1] == 'P': if s[u] == 'D': ret += dfs(u, A+[s[u]]) elif A[-1] == 'D': if s[u] == 'C': ret += dfs(u, A+[s[u]]) elif A[-1] == 'C': if s[u] == 'A': ret += dfs(u, A+[s[u]]) return ret ans = 0 for v in range(n): if s[v] == 'P': ans += dfs(v, ['P']) ans %= mod print(ans%mod)