#include <bits/stdc++.h>
using namespace std;

const long long int adjustment = 1000000007;

class Node{
public:
    string info;
    int num;
};

list<Node> l[1001];
Node nodes[1001];

long long int Con(int n,int r){
    long long int result = 1;
    for(int i=n;i>n-r;i--){
        result *= i;
    }
    for(int i=1;i<=r;i++){
        result /= i;
    }
    return result;
}

long long int DFS(Node node){


    long long int sum = 0;

    if(l[node.num].size() == 0){
        if(node.info == "E"){
            sum = 1;
        }
        else{ //E?
            sum = 2;
        }
    }
    else {
        if(node.info == "E?") {
            sum = 1;
            for (list<Node>::iterator it = l[node.num].begin(); it != l[node.num].end(); it++) {
                sum *= DFS(*it);
                sum %= adjustment;
            }
            sum++;
            sum %= adjustment;
        }
        else if(node.info == "E"){
            sum = 1;
            for (list<Node>::iterator it = l[node.num].begin(); it != l[node.num].end(); it++) {
                sum *= DFS(*it);
                sum %= adjustment;
            }
        }
        else if(node.info == "A?"){
            sum = 0;
            for (list<Node>::iterator it = l[node.num].begin(); it != l[node.num].end(); it++) {
                sum += DFS(*it);
                sum %= adjustment;
            }
            sum++;
            sum %= adjustment;
        }
        else if(node.info == "A"){
            sum = 0;
            for (list<Node>::iterator it = l[node.num].begin(); it != l[node.num].end(); it++) {
                sum += DFS(*it);
                sum %= adjustment;
            }
        }
        else if(node.info == "R?"){
            sum = 0;
            int childcount = l[node.num].size();
            long long int childsum[childcount];
            int k = 0;
            for (list<Node>::iterator it = l[node.num].begin(); it != l[node.num].end(); it++) {
                childsum[k] = DFS(*it);
                childsum[k] %= adjustment;
                k++;
            }
            long long int m = 1 << childcount;
            for(long long int i=1; i<m; i++){
                long long int selectsum = 1;
                for(int j=0; j<childcount; j++){
                    if( (i >> j) & 1 ){
                        selectsum = (selectsum*childsum[j]) & adjustment;
                    }
                }
                sum = (sum + selectsum) % adjustment;
            }
            sum = (sum+1) % adjustment;
        }
        else if(node.info == "R"){
            sum = 0;
            int childcount = l[node.num].size();
            long long int childsum[childcount];
            int k = 0;
            for (list<Node>::iterator it = l[node.num].begin(); it != l[node.num].end(); it++) {
                childsum[k] = DFS(*it);
                childsum[k] %= adjustment;
                k++;
            }
            long long int m = 1 << childcount;
            for(long long int i=1; i<m; i++){
                long long int selectsum = 1;
                for(int j=0; j<childcount; j++){
                    if( (i >> j) & 1 ){
                        selectsum = (selectsum*childsum[j]) % adjustment;
                    }
                }
                sum = (sum + selectsum) % adjustment;
            }

        }
    }

    return sum;

}

int main() {

    int n;

    cin >> n;

    for(int i=1;i<=n;i++){
        string s;
        cin >> s;
        nodes[i].info = s;
        nodes[i].num = i;
    }

    for(int i=1;i<n;i++){
        int s,t;
        scanf(" %d %d",&s,&t);
        l[s].push_back(nodes[t]);
    }

    cout << DFS(nodes[1]) % adjustment << endl;

    return 0;
}

Measured memory_bytes: 3396