import java.util.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); char[] arr = sc.next().toCharArray(); long[] counts = new long[n]; ArrayList[] lists = new ArrayList[n]; for (int i = 0; i < n; i++) { if (arr[i] == 'D') { lists[i] = new ArrayList(); } } for (int i = 0; i < m; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; if (arr[a] == 'P') { if (arr[b] == 'D') { counts[b]++; } } else if (arr[a] == 'D') { if (arr[b] == 'P') { counts[a]++; } else if (arr[b] == 'C') { lists[a].add(b); } } else if (arr[a] == 'C') { if (arr[b] == 'D') { lists[b].add(a); } else if (arr[b] == 'A') { counts[b]++; } } else if (arr[a] == 'A') { if (arr[b] == 'C') { counts[b]++; } } } long total = 0; for (int i = 0; i < n; i++) { if (arr[i] != 'D') { continue; } for (int x : lists[i]) { total += counts[i] * counts[x]; total %= MOD; } } System.out.println(total); } }