MOD = 10 ** 9 + 7 N, M = gets.split.map(&:to_i) S = gets.chomp E = Hash.new { |h, k| h[k] = [] } M.times do u, v = gets.split.map(&:to_i) u -= 1 v -= 1 E[u] << v E[v] << u end counter = Hash.new(0) que = [] S.chars.each_with_index do |s, idx| next if s != 'P' que << idx counter[idx] += 1 end L = ['D', 'C', 'A'] 3.times do |i| temp_counter = Hash.new(0) temp_que = Hash.new until que.empty? v = que.shift E[v].each do |u| next if S[u] != L[i] temp_counter[u] += counter[v] temp_counter[u] %= MOD temp_que[u] = true end end counter = temp_counter que = temp_que.keys end pp counter.values.sum % MOD