object Main extends App{
  import scala.io.StdIn.readLine
  val n = readLine().toInt
  val nodes = Array.tabulate(n){_ ⇒ Node(readLine().trim())}
  for (_ ← 1 until n){
    val Array(s, t) = readLine().split(' ').map(_.toInt)
    nodes(s - 1).addChile(nodes(t - 1))
  }
  println(nodes(0).pattern())
}
object Node {
  def apply(str:String):Node = {
    str match{
      case "E" ⇒ new MaterialNode
      case "E?" ⇒ new OptMaterialNode
      case "A" ⇒ new AltNode
      case "A?" ⇒ new OptAltNode
      case "R" ⇒ new OrNode
      case "R?" ⇒ new OptOrNode
      case _ ⇒ ???
    }
  }
}
sealed trait Node{
  protected var mChildren:List[Node] = Nil
  def addChile(node:Node):Unit = mChildren ::= node
  def pattern():Long = rawPattern() % mod
  protected def mod = 1000000007l
  protected def rawPattern():Long
}
sealed trait OptNode extends Node{
  override def pattern() = (super.pattern() + 1) % mod
}
class MaterialNode extends Node {
  override def rawPattern():Long = mChildren.foldLeft(1l){case (prev, node) ⇒ prev * node.pattern() % mod}
}
class OptMaterialNode extends MaterialNode with OptNode
class AltNode extends Node {
  override def rawPattern():Long = mChildren.map{node ⇒ node.pattern()}.sum
}
class OptAltNode extends AltNode with OptNode
class OrNode extends Node{
  override def rawPattern(): Long = mChildren.foldLeft(1l){case (prev, node) ⇒ prev * (node.pattern() + 1) % mod} + mod - 1
}
class OptOrNode extends OrNode with OptNode

