# import sys; input = sys.stdin.buffer.readline # sys.setrecursionlimit(10**7) from collections import defaultdict from collections import deque con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) class Graph(object): def __init__(self): self.graph = defaultdict(list) def __len__(self): return len(self.graph) def add_edge(self, a, b): self.graph[a].append(b) #処理内容 def main(): N, M = getlist() S = input() G = Graph() DP = [0] * N for i in range(N): if S[i] == "P": DP[i] = 1 for i in range(M): a, b = getlist() a -= 1; b -= 1 if (S[a] == "P" and S[b] =="D") or (S[a] == "D" and S[b] =="C") or (S[a] == "C" and S[b] =="A"): G.add_edge(a, b) if (S[a] == "A" and S[b] =="C") or (S[a] == "C" and S[b] =="D") or (S[a] == "D" and S[b] =="P"): G.add_edge(b, a) for i in range(N): if S[i] == "P": for v in G.graph[i]: DP[v] += DP[i] for i in range(N): if S[i] == "D": for v in G.graph[i]: DP[v] += DP[i] for i in range(N): if S[i] == "C": for v in G.graph[i]: DP[v] += DP[i] ans = 0 for i in range(N): if S[i] == "A": ans += DP[i] print(ans % con) if __name__ == '__main__': main()