n = gets.to_i
type = {}
(1..n).map {|i| type[i] = gets.chomp}
g = {}
(1..n).each {|i| g[i] = []}
(n - 1).times do
    i, j = gets.split.map(&:to_i)
    g[i] << j
end
def f(g, type, i)
    k = (type[i].size > 1 ? 1 : 0)
    if type[i][0] == ?A
        g[i].each do |j|
            k += f(g, type, j)
        end
    elsif type[i][0] == ?R
        k += g[i].map {|j| 1 + f(g, type, j)}.inject(:*) - 1
    elsif type[i][0] == ?E
        if g[i].empty?
            k += 1
        else
            k += g[i].map {|j| f(g, type, j)}.inject(:*)
        end
    end
    k % 1_000_000_007
end
p f(g, type, 1)

