#include <bits/stdc++.h>
using namespace std;
const long long N = 60;
long long n, a[N], b[N];
long long ans1[N], ans2[N];
long long tms[N], fl;
char s[N];
const long long mo1 = 3000000019ll;
const long long mo2 = 3000000037ll;
long long power(long long x, long long y, long long mo) {
  long long s = 1;
  for (; y; y /= 2, x = 1ll * x * x % mo)
    if (y & 1) s = 1ll * s * x % mo;
  return s;
}
long long CRT(long long ans1, long long ans2) {
  long long v1 = 1ll * ans1 * power(mo2, mo1 - 2, mo1) % mo1 * mo2;
  long long v2 = 1ll * ans2 * power(mo1, mo2 - 2, mo2) % mo2 * mo1;
  long long ans = (1ull * v1 + 1ull * v2) % (1ll * mo1 * mo2);
  assert(ans % mo1 == ans1);
  assert(ans % mo2 == ans2);
  return ans;
}
struct solver {
  long long t[N][N], mo;
  long long op[N * N], opx[N * N], opy[N * N];
  void gauss(long long n) {
    for (long long i = (long long)(0); i <= (long long)(n - 1); i++) {
      long long p = -1;
      for (long long j = (long long)(i); j <= (long long)(n); j++)
        if (t[j][i]) p = j;
      assert(p != -1);
      if (p != i) {
        for (long long j = (long long)(0); j <= (long long)(n); j++)
          swap(t[i][j], t[p][j]);
        op[++*op] = -1;
        opx[*op] = i;
        opy[*op] = p;
      }
      long long v = power(t[i][i], mo - 2, mo);
      for (long long j = (long long)(0); j <= (long long)(n); j++)
        if (j != i) {
          long long val = 1ll * (mo - t[j][i]) * v % mo;
          op[++*op] = val;
          opx[*op] = j;
          opy[*op] = i;
          for (long long k = (long long)(0); k <= (long long)(n); k++)
            t[j][k] = (t[j][k] + 1ll * val * t[i][k]) % mo;
        }
    }
  }
  void init() {
    long long I2 = (mo + 1) / 2;
    *op = 0;
    memset(t, 0, sizeof(t));
    for (long long i = (long long)(0); i <= (long long)(n - 1); i++) {
      t[a[i]][i] = (t[a[i]][i] + I2) % mo;
      t[b[i]][i] = (t[b[i]][i] + I2) % mo;
    }
    for (long long i = (long long)(0); i <= (long long)(n - 1); i++)
      t[i][i] = (t[i][i] + mo - 1) % mo;
    gauss(n - 1);
  }
  void solve(char *s, long long p, long long *ans) {
    long long I2 = (mo + 1) / 2;
    for (long long i = (long long)(0); i <= (long long)(n); i++) ans[i] = 0;
    for (long long i = (long long)(0); i <= (long long)(n - 1); i++)
      if (s[i] == 'R') {
        ans[a[i]] = (ans[a[i]] + mo - I2) % mo;
        ans[b[i]] = (ans[b[i]] + I2) % mo;
      }
    ans[0] = (ans[0] + 1) % mo;
    ans[p] = (ans[p] + mo - 1) % mo;
    for (long long i = (long long)(0); i <= (long long)(n - 1); i++)
      ans[i] = (mo - ans[i]) % mo;
    for (long long i = (long long)(1); i <= (long long)(*op); i++)
      if (op[i] == -1)
        swap(ans[opx[i]], ans[opy[i]]);
      else
        ans[opx[i]] = (ans[opx[i]] + 1ll * op[i] * ans[opy[i]]) % mo;
    for (long long i = (long long)(0); i <= (long long)(n - 1); i++)
      ans[i] = 1ll * ans[i] * power(t[i][i], mo - 2, mo) % mo;
  }
} S1, S2;
signed main() {
  scanf("%lld", &n);
  for (long long i = (long long)(0); i <= (long long)(n - 2); i++)
    scanf("%lld%lld", &a[i], &b[i]);
  for (long long i = (long long)(0); i <= (long long)(n - 2); i++)
    --a[i], --b[i];
  a[n - 1] = b[n - 1] = n - 1;
  S1.mo = mo1;
  S2.mo = mo2;
  S1.init();
  S2.init();
  long long Q, p;
  scanf("%lld", &Q);
  while (Q--) {
    scanf("%lld%s", &p, s);
    p = p - 1;
    s[n - 1] = 'B';
    fl = 0;
    S1.solve(s, p, ans1);
    S2.solve(s, p, ans2);
    for (long long i = (long long)(0); i <= (long long)(n - 1); i++)
      tms[i] = CRT(ans1[i], ans2[i]);
    for (long long i = (long long)(0); i <= (long long)(n - 1); i++)
      if (((s[i] == 'R') + tms[i]) % 2 == 1) fl = 1;
    for (long long i = (long long)(0); i <= (long long)(n - 1); i++)
      if (tms[i]) {
        long long x = i, fll = 0;
        for (long long j = (long long)(1); j <= (long long)(n); j++) {
          if (x == p) fll = 1;
          x = (tms[x] & 1 ? b[x] : a[x]);
        }
        if (!fll) fl = 1;
      }
    if (fl)
      puts("-1");
    else {
      long long ans = 0;
      for (long long i = (long long)(0); i <= (long long)(n - 1); i++)
        ans += tms[i];
      printf("%lld\n", ans);
    }
  }
}
