#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 60, mod1 = 1e9 + 7, mod2 = 1e9 + 9;
long long A[N][N], B[N][N], a[N][N];
struct d1 {
  const int mod = mod1;
  long long ksm(long long a, int b) {
    int ans = 1;
    for (; b; b >>= 1) {
      if (b & 1) ans = ans * a % mod;
      a = a * a % mod;
    }
    return ans;
  }
  long long b[N][N];
  void solve(int n) {
    memcpy(a, A, sizeof(a));
    memcpy(b, B, sizeof(b));
    for (int i = (int)(1); i <= (int)(n); i++) {
      for (int j = (int)(i); j <= (int)(n); j++)
        if (a[j][i]) {
          swap(a[j], a[i]);
          swap(b[j], b[i]);
          break;
        }
      long long zs = ksm(a[i][i], mod - 2);
      for (int j = (int)(1); j <= (int)(n); j++) {
        a[i][j] = a[i][j] * zs % mod;
        b[i][j] = b[i][j] * zs % mod;
      }
      for (int j = (int)(1); j <= (int)(n); j++)
        if (i != j) {
          zs = a[j][i];
          for (int k = (int)(1); k <= (int)(n); k++) {
            if (a[i][k]) a[j][k] = (a[j][k] - a[i][k] * zs) % mod;
            b[j][k] = (b[j][k] - b[i][k] * zs) % mod;
          }
        }
    }
  }
  void bao(int n, long long aa[], long long AA[]) {
    memset(AA, 0, sizeof(AA));
    for (int i = (int)(1); i <= (int)(n); i++) {
      for (int j = (int)(1); j <= (int)(n); j++)
        AA[i] = (AA[i] + aa[j] * b[i][j]) % mod;
      AA[i] = (AA[i] + mod) % mod;
    }
  }
} T1;
struct d2 {
  const int mod = mod2;
  long long ksm(long long a, int b) {
    int ans = 1;
    for (; b; b >>= 1) {
      if (b & 1) ans = ans * a % mod;
      a = a * a % mod;
    }
    return ans;
  }
  long long b[N][N];
  void solve(int n) {
    memcpy(a, A, sizeof(a));
    memcpy(b, B, sizeof(b));
    for (int i = (int)(1); i <= (int)(n); i++) {
      for (int j = (int)(i); j <= (int)(n); j++)
        if (a[j][i]) {
          swap(a[j], a[i]);
          swap(b[j], b[i]);
          break;
        }
      long long zs = ksm(a[i][i], mod - 2);
      for (int j = (int)(1); j <= (int)(n); j++) {
        a[i][j] = a[i][j] * zs % mod;
        b[i][j] = b[i][j] * zs % mod;
      }
      for (int j = (int)(1); j <= (int)(n); j++)
        if (i != j) {
          zs = a[j][i];
          for (int k = (int)(1); k <= (int)(n); k++) {
            if (a[i][k]) a[j][k] = (a[j][k] - a[i][k] * zs) % mod;
            b[j][k] = (b[j][k] - b[i][k] * zs) % mod;
          }
        }
    }
  }
  void bao(int n, long long aa[], long long AA[]) {
    memset(AA, 0, sizeof(AA));
    for (int i = (int)(1); i <= (int)(n); i++) {
      for (int j = (int)(1); j <= (int)(n); j++)
        AA[i] = (AA[i] + aa[j] * b[i][j]) % mod;
      AA[i] = (AA[i] + mod) % mod;
    }
  }
} T2;
int b[N], r[N];
bool bj[N];
char s[N];
long long aa[N], bb[N], AA[N], BB[N], ans[N];
vector<int> e[N];
void dfs(int p) {
  if (bj[p])
    return;
  else
    bj[p] = 1;
  for (auto i : e[p]) dfs(i);
}
int main() {
  int n = read();
  long long inv2 = T1.ksm(mod2, mod1 - 2), inv1 = T2.ksm(mod1, mod2 - 2);
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    b[i] = read();
    r[i] = read();
    A[r[i]][i]--;
    A[b[i]][i]--;
    A[i][i] += 2;
    B[i][i] = 1;
  }
  T1.solve(n - 1);
  T2.solve(n - 1);
  int q = read();
  while (q--) {
    int v = read();
    scanf("%s", s + 1);
    for (int i = (int)(1); i <= (int)(n - 1); i++)
      aa[i] = bb[i] = (s[i] == 'R') + (i == 1) - (i == v);
    for (int i = (int)(1); i <= (int)(n - 1); i++)
      if (s[i] == 'R') {
        aa[b[i]]--;
        bb[b[i]]--;
      }
    memset(AA, 0, sizeof(AA));
    memset(BB, 0, sizeof(BB));
    T1.bao(n - 1, aa, AA);
    T2.bao(n - 1, bb, BB);
    for (int i = (int)(1); i <= (int)(n - 1); i++) {
      ans[i] = (AA[i] * inv2 % mod1 * mod2 + BB[i] * inv1 % mod2 * mod1) %
               ((long long)mod1 * mod2);
    }
    for (int i = (int)(1); i <= (int)(n - 1); i++)
      for (int j = (int)(1); j <= (int)(n - 1); j++) aa[i] -= A[i][j] * ans[j];
    int f = 1;
    for (int i = (int)(1); i <= (int)(n - 1); i++) {
      if (aa[i] || (ans[i] - (s[i] == 'R')) < 0) f = 0;
      e[i].clear();
    }
    memset(bj, 0, sizeof(bj));
    for (int i = (int)(1); i <= (int)(n - 1); i++) {
      if (s[i] == 'B')
        e[b[i]].push_back(i);
      else
        e[r[i]].push_back(i);
    }
    dfs(v);
    for (int i = (int)(1); i <= (int)(n - 1); i++)
      if (!bj[i] && ans[i]) {
        f = 0;
      }
    if (!f)
      puts("-1");
    else {
      long long sum = 0;
      for (int i = (int)(1); i <= (int)(n - 1); i++)
        sum += ans[i] * 2 - (s[i] == 'R');
      writeln(sum);
    }
  }
}
