N,M =map(int,input().split()) str =input() pdca ={l:set() for l in "PDCA"} line ={i+1:set() for i in range(N)} for i,st in enumerate(str): pdca[st].add(i+1) for i in range(M): s,t =map(int,input().split()) line[s].add(t) line[t].add(s) sum = 0 for np in pdca["P"]: for nd in line[np]: if nd in pdca["D"]: for nc in line[nd]: if nc in pdca["C"]: for nd in line[nc]: if nd in pdca["A"]: sum +=1 print(sum%1000000007)