import sys input=sys.stdin.readline N,M=map(int,input().split()) mod=10**9+7 S=input() toD=[0 for i in range(N)] toC=[0 for i in range(N)] toA=[0 for i in range(N)] L=[[]for i in range(N)] for i in range(M): a,b=map(int,input().split()) L[a-1].append(b-1) L[b-1].append(a-1) #print(L) for i in range(N): if S[i]=="P": for j in L[i]: if S[j]=="D": toD[j]+=1 #print(toD) for i in range(N): if toD[i]>0: for j in L[i]: if S[j]=="C": toC[j]+=toD[i] #print(toC) for i in range(N): if toC[i]>0: for j in L[i]: if S[j]=="A": toA[j]+=toC[i] print(sum(toA)%mod)