import collections mod = 10**9 + 7 n, m = map(int, input().split()) s = input() graph = [[] for i in range(n)] edges = { 'PD': [], 'DC': [], 'CA': [], } for _ in range(m): u, v = map(lambda x: int(x) - 1, input().split()) if s[u] == 'P': if s[v] == 'D': edges['PD'].append((u, v)) elif s[u] == 'D': if s[v] == 'C': edges['DC'].append((u, v)) elif s[v] == 'P': edges['PD'].append((v, u)) elif s[u] == 'C': if s[v] == 'A': edges['CA'].append((u, v)) elif s[v] == 'D': edges['DC'].append((v, u)) elif s[u] == 'A': if s[v] == 'C': edges['CA'].append((v, u)) cnt = collections.defaultdict(int) for u, v in edges['PD']: cnt[v] += 1 for u, v in edges['DC']: cnt[v] += cnt[u] total = 0 for u, v in edges['DC']: total += cnt[u] print(total % mod)