from collections import defaultdict def main(): mod = 10 ** 9 + 7 n, m = map(int, input().split()) s = input() adj = defaultdict(list) for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 if s[a] + s[b] in ["PD", "DC", "CA"]: adj[a].append(b) if s[b] + s[a] in ["PD", "DC", "CA"]: adj[b].append(a) wd = "PDCA" # dp[i][v]:PDCAのi文字目まで来ていて,終点が頂点vの経路数 dp = [[0 for _ in range(n)] for _ in range(4)] # 1文字目 for i in range(n): if s[i] == wd[0]: dp[0][i] = 1 # 2文字目以降 for i in range(1, len(wd)): for u in range(n): for v in adj[u]: if s[v] == wd[i]: dp[i][v] += dp[i - 1][u] dp[i][v] %= mod res = sum(dp[3]) % mod print(res) if __name__ == "__main__": main()