TYPES = "PDCA" MOD = 10**9 + 7 N,M = gets.split.map(&:to_i) S = gets.chomp V = Array.new(N + 1, -1) G = Array.new(N + 1){[]} dp = Array.new(4){ Array.new(N + 1, 0) } (1 .. N).each do |v| t = TYPES.index(S[v - 1]) V[v] = t end M.times do a,b = gets.split.map(&:to_i) G[a] << b G[b] << a end (1 .. N).each do |v| dp[0][v] = 1 if V[v] == 0 end (1 .. 3).each do |t| (1 .. N).each do |v| next unless V[v] == t dp[t][v] = G[v].inject(0) do |s, u| V[u] == t - 1 ? s + dp[t - 1][u] : s end end end puts dp[3].inject(0){|s,v| (s + v) % MOD }