import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); String S = sc.next(); int[] u = new int[M]; int[] v = new int[M]; for(int i = 0; i < M; i++) { u[i] = sc.nextInt() - 1; v[i] = sc.nextInt() - 1; } sc.close(); long mod = (long)Math.pow(10, 9) + 7; int cp = 0; int cd = 0; int cc = 0; int ca = 0; int[] node = new int[N]; for(int i = 0; i < N; i++) { char c = S.charAt(i); if(c == 'P') { node[i] = cp; cp++; }else if(c == 'D') { node[i] = cd; cd++; }else if(c == 'C') { node[i] = cc; cc++; }else if(c == 'A') { node[i] = ca; ca++; } } if(cp == 0 || cd == 0 || cc == 0 || ca == 0) { System.out.println(0); System.exit(0); } long[] C = new long[cc]; for(int i = 0; i < M; i++) { char cu = S.charAt(u[i]); char cv = S.charAt(v[i]); if(cu == 'C' && cv == 'A') { C[node[u[i]]]++; }else if(cu == 'A' && cv == 'C'){ C[node[v[i]]]++; } } long[] D = new long[cd]; for(int i = 0; i < M; i++) { char cu = S.charAt(u[i]); char cv = S.charAt(v[i]); if(cu == 'D' && cv == 'C') { D[node[u[i]]] += C[node[v[i]]]; D[node[u[i]]] %= mod; }else if(cu == 'C' && cv == 'D'){ D[node[v[i]]] += C[node[u[i]]]; D[node[v[i]]] %= mod; } } long[] P = new long[cp]; for(int i = 0; i < M; i++) { char cu = S.charAt(u[i]); char cv = S.charAt(v[i]); if(cu == 'P' && cv == 'D') { P[node[u[i]]] += D[node[v[i]]]; P[node[u[i]]] %= mod; }else if(cu == 'D' && cv == 'P'){ P[node[v[i]]] += D[node[u[i]]]; P[node[v[i]]] %= mod; } } long ans = 0; for(long i : P) { ans += i; ans %= mod; } System.out.println(ans); } }