using System.Linq;
using System.Collections.Generic;
using System;

public static class combi
{
    public static IEnumerable<IEnumerable<T>> Comb<T>(this IEnumerable<T> items, int r)
    {
        if (r == 0)
        {
            yield return Enumerable.Empty<T>();
        }
        else
        {
            var i = 1;
            foreach (var x in items)
            {
                var xs = items.Skip(i);
                foreach (var c in Comb(xs, r - 1))
                    yield return c.Before(x);
                i++;
            }
        }
    }
    public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first)
    {
        yield return first;
        foreach (var i in items)
            yield return i;
    }
}

public class Node
{
    public string type { get; set; }
    public bool option { get; set; }
    public List<int> child { get; set; }
}

public class hello
{
    const int MOD = 1000000007;
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var nodes = new Node[n];
        for (int i = 0; i < n; i++)
        {
            var t = "or";
            var s = Console.ReadLine().Trim();
            if (s[0] == 'A') t = "aLt";
            else if (s[0] == 'E') t = "e";
            nodes[i] = new Node { child = new List<int>(), type = t, option = s.Length == 2 ? true : false };
        }
        string S;
        for (; (S = Console.ReadLine()) != null;)
        {
            string[] line = S.Trim().Split(' ');
            var a = int.Parse(line[0]) - 1;
            var b = int.Parse(line[1]) - 1;
            nodes[a].child.Add(b);
        }
        var ans = goRec(nodes, 0);
        Console.WriteLine(ans);

    }
  static int goRec ( Node[] nodes , int n)
    {
        var w = nodes[n];
        if (w.type == "e")
        {
            if (w.child.Count() == 0) return w.option ? 2 : 1;
            else
            {
                var ans = 1L;
                foreach (var x in w.child)
                {
                    ans *= goRec(nodes, x);
                    ans %= MOD;
                }
                return w.option ? ((int)ans + 1) % MOD : (int)ans;
            }
        }
        else if (w.type == "aLt")
        {
            var ans = 0L;
            foreach (var x in w.child)
            {
                ans += goRec(nodes, x);
                ans %= MOD;
            }
            return w.option ? ((int)ans + 1) % MOD : (int)ans;
        }
        else
        {
            var cc = w.child.Count();
            var t = new int[cc];
            var p = 0;
            foreach(var x in w.child)
                t[p++] = goRec(nodes, x);
            var gor = getOR(t, cc);
            return w.option ? (gor+ 1) % MOD : gor;
        }
    }
    static int getOR (int [] a , int n)
    {
        var ans = 0;
        for (int i = 1; i <= n; i++)
        {
            var b = a.Comb(i);
            var t = 0L;
            foreach (var x in b)
            {
                var t2 = 1L;
                foreach (var y in x)
                {
                    t2 *= y;
                    t2 %= MOD;
                }
                t +=(int) t2;
                t %= MOD;
            }
            ans +=(int) t;
            ans %= MOD;
        }
        return ans;
    }
}



Measured memory_bytes: 20264