#include <bits/stdc++.h>
using namespace std;
const int N = 60;
const unsigned long long mod = 18446744065119617029ULL;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while (!isdigit(ch) && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
unsigned long long add(unsigned long long a, unsigned long long b) {
  return a < mod - b ? a + b : a - (mod - b);
}
unsigned long long sub(unsigned long long a, unsigned long long b) {
  return (!b) ? a : add(a, mod - b);
}
unsigned long long mul(unsigned long long a, unsigned long long b) {
  unsigned long long ret = 0;
  while (b) {
    if (b & 1) ret = add(ret, a);
    a = add(a, a), b >>= 1;
  }
  return ret;
}
unsigned long long qpow(unsigned long long a, unsigned long long b) {
  unsigned long long ret = 1;
  while (b) {
    if (b & 1) ret = mul(ret, a);
    a = mul(a, a), b >>= 1;
  }
  return ret;
}
unsigned long long inv(unsigned long long a) { return qpow(a, mod - 2); }
int n, b[N], r[N], q, sz, A[N][N];
char s[N];
unsigned long long a[N][N << 1], inv_a[N][N], x[N], y[N], z[N], Z[N];
bool vis[N];
void getinv() {
  int m = sz + sz;
  for (int i = 1; i <= sz; i++) a[i][i + sz] = 1;
  for (int i = 1; i <= sz; i++) {
    if (!a[i][i])
      for (int j = i + 1; j <= sz; j++)
        if (a[j][i]) {
          swap(a[i], a[j]);
          break;
        }
    unsigned long long t = inv(a[i][i]);
    for (int j = i; j <= m; j++) a[i][j] = mul(a[i][j], t);
    for (int j = 1; j <= sz; j++)
      if (i ^ j) {
        unsigned long long t = a[j][i];
        for (int k = i; k <= m; k++) a[j][k] = sub(a[j][k], mul(t, a[i][k]));
      }
  }
  for (int i = 1; i <= sz; i++)
    for (int j = 1; j <= sz; j++) inv_a[i][j] = a[i][j + sz];
}
void mul() {
  for (int i = 1; i <= sz; i++) {
    x[i] = 0;
    for (int j = 1; j <= sz; j++) x[i] = add(x[i], mul(inv_a[i][j], z[j]));
  }
}
int main() {
  cin >> n;
  sz = n - 1;
  for (int i = 1; i < n; i++) b[i] = gi(), r[i] = gi();
  for (int i = 1; i <= sz; i++) {
    a[i][i] = 2;
    a[r[i]][i] = sub(a[r[i]][i], 1);
    a[b[i]][i] = sub(a[b[i]][i], 1);
    A[i][i] = 2;
    --A[r[i]][i];
    --A[b[i]][i];
  }
  getinv();
  cin >> q;
  while (q--) {
    int v = gi();
    scanf("%s", s + 1);
    for (int i = 1; i <= sz; i++) {
      z[i] = sub((s[i] == 'R') + (i == 1), i == v);
      Z[i] = (s[i] == 'R') + (i == 1) - (i == v);
      for (int j = 1; j <= sz; j++)
        if (b[j] == i && s[j] == 'R') z[i] = sub(z[i], 1), --Z[i];
    }
    mul();
    bool fl = 1;
    for (int i = 1; i <= sz && fl; i++) {
      unsigned long long tmp = 0;
      for (int j = 1; j <= sz; j++) tmp += x[j] * A[i][j];
      if (tmp != Z[i]) fl = 0;
    }
    for (int i = 1; i <= sz && fl; i++) {
      if (s[i] == 'R' && !x[i]) fl = 0;
      y[i] = x[i] - (s[i] == 'R');
    }
    for (int i = 1; i <= sz && fl; i++)
      if (x[i] || y[i]) {
        memset(vis, 0, sizeof(vis));
        vis[n] = 1;
        int u = i;
        while (!vis[u] && u != v) vis[u] = 1, u = (s[u] == 'R' ? r[u] : b[u]);
        if (vis[u]) fl = 0;
      }
    if (!fl)
      cout << "-1\n";
    else {
      unsigned long long ans = 0;
      for (int i = 1; i <= sz; i++) ans += x[i] + y[i];
      cout << ans << '\n';
    }
  }
  return 0;
}
