using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Program { static int[] pathCount; static void Main() { Console.SetIn(new System.IO.StreamReader(Console.OpenStandardInput((int)Math.Pow(10,5)))); string[] arr = Console.ReadLine().Split(' '); int N = int.Parse(arr[0]); int M = int.Parse(arr[1]); string s = Console.ReadLine(); List paths = new List(); List DCindex = new List(); pathCount = Enumerable.Repeat(0, N).ToArray(); for (int i = 0; i < M; i++) { arr = Console.ReadLine().Split(' '); Path p = new Path(); p.From = int.Parse(arr[0]) - 1; p.To = int.Parse(arr[1]) - 1; if(s.Substring(p.From, 1) == "P" && s.Substring(p.To, 1) == "D" || s.Substring(p.From, 1) == "D" && s.Substring(p.To, 1) == "C" || s.Substring(p.From, 1) == "C" && s.Substring(p.To, 1) == "A") { p.From = int.Parse(arr[0]) - 1; p.To = int.Parse(arr[1]) - 1; paths.Add(p); if (s.Substring(p.From, 1) == "P" && s.Substring(p.To, 1) == "D") { pathCount[p.To]++; } else if (s.Substring(p.From, 1) == "D" && s.Substring(p.To, 1) == "C") { DCindex.Add(paths.Count - 1); } else if (s.Substring(p.From, 1) == "C" && s.Substring(p.To, 1) == "A") { pathCount[p.From]++; } } else if(s.Substring(p.To, 1) == "P" && s.Substring(p.From, 1) == "D" || s.Substring(p.To, 1) == "D" && s.Substring(p.From, 1) == "C" || s.Substring(p.To, 1) == "C" && s.Substring(p.From, 1) == "A") { p.To = int.Parse(arr[0]) - 1; p.From = int.Parse(arr[1]) - 1; paths.Add(p); if (s.Substring(p.From, 1) == "P" && s.Substring(p.To, 1) == "D") { pathCount[p.To]++; } else if (s.Substring(p.From, 1) == "D" && s.Substring(p.To, 1) == "C") { DCindex.Add(paths.Count - 1); } else if (s.Substring(p.From, 1) == "C" && s.Substring(p.To, 1) == "A") { pathCount[p.From]++; } } } if(DCindex.Count == 0) { Console.WriteLine("0"); return; } int mod = 1000000007; ulong sum = 0; for (int i = 0; i < DCindex.Count; i++) { Path pDC = paths[DCindex[i]]; sum += (ulong)(pathCount[pDC.To] * pathCount[pDC.From]); sum %= (ulong)mod; } Console.WriteLine(sum); } } class Path { public int From { get; set; } public int To { get; set; } }