from collections import defaultdict n, m = map(int, input().split()) s = input() G = defaultdict(list) for _ in range(m): u, v = map(int, input().split()) u -= 1 v -= 1 if s[u] == 'P' and s[v] == 'D': G[v].append(u) elif s[u] == 'D' and s[v] == 'P': G[u].append(v) elif s[u] == 'D' and s[v] == 'C': G[v].append(u) elif s[v] == 'D' and s[u] == 'C': G[u].append(v) elif s[u] == 'C' and s[v] == 'A': G[v].append(u) elif s[u] == 'A' and s[v] == 'C': G[u].append(v) mod = 10**9 + 7 DP = [0 for _ in range(n)] for ss in ['A', 'C', 'D']: for i in range(n): if s[i] == ss: if ss == 'A': DP[i] = 1 for j in G[i]: DP[j] += DP[i] DP[j] %= mod ans = 0 for i in range(n): if s[i] == 'P': ans += DP[i] ans %= mod print(ans)