#yuki762 n,m=map(int,raw_input().split()) s=raw_input() lc=[0]*n ld=[0]*n l=[] for i in range(m): x,y=map(int,raw_input().split()) x-=1 y-=1 if s[x]=='P' and s[y]=='D': ld[y]+=1 elif s[x]=='D' and s[y]=='P': ld[x]+=1 elif s[x]=='D' and s[y]=='C': l.append([x,y]) elif s[x]=='C' and s[y]=='D': l.append([y,x]) elif s[x]=='C' and s[y]=='A': lc[x]+=1 elif s[x]=='A' and s[y]=='C': lc[y]+=1 res=0 for i in l: res+=(ld[i[0]]*lc[i[1]]) res%=10**9+7 print res