n,m = map(int,input().split()) s = input() g = [[] for _ in range(n)] for _ in range(m): a,b = map(int,input().split()) g[a-1].append(b-1) g[b-1].append(a-1) MOD = 10**9+7 r = [int(si=="P") for si in s] for A,B in ["PD","DC","CA"]: nr = [0]*n for i in range(n): if r[i] and s[i] == A: for c in g[i]: if s[c] == B: nr[c] += r[i] nr[c] %= MOD r = nr print(sum(r)%MOD)