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) res = [0] def dfs(v, A): if len(A) == 4: res[0] += 1 res[0] %= mod return for u in g[v]: if A[-1] == 'P': if s[u] == 'D': dfs(u, A+[s[u]]) elif A[-1] == 'D': if s[u] == 'C': dfs(u, A+[s[u]]) elif A[-1] == 'C': if s[u] == 'A': dfs(u, A+[s[u]]) return for v in range(n): if s[v] == 'P': dfs(v, ['P']) print(res[0]%mod)