MOD = 10**9 + 7 N, M = gets.split.map(&:to_i) S = gets.chomp graph = Array.new(N) { [] } PDCA = "PDCA" M.times do (s, u), (t, v) = gets.split.map { |s| i = s.to_i - 1; [PDCA.index(S[i]), i] }.minmax graph[v] << u if s + 1 == t end vertices = Array.new(4) { [] } N.times do |u| vertices[PDCA.index(S[u])] << u end dp = [1] * N vertices[1, 3].each do |us| us.each do |u| dp[u] = graph[u].sum { |v| dp[v] } % MOD end end puts vertices[3].sum { |u| dp[u] } % MOD