#include <bits/stdc++.h>
using namespace std;
using u64 = uint64_t;
using i64 = int64_t;
template <class T>
inline void cmin(T& a, T b) {
  ((a > b) && (a = b));
}
template <class T>
inline void cmax(T& a, T b) {
  ((a < b) && (a = b));
}
char IO;
template <class T = int>
T rd() {
  T s = 0;
  int f = 0;
  while (!isdigit(IO = getchar())) f |= IO == '-';
  do s = (s << 1) + (s << 3) + (IO ^ '0');
  while (isdigit(IO = getchar()));
  return f ? -s : s;
}
const int N = 180;
const u64 P1 = (u64)9e18 + 41, P2 = (u64)9e18 + 53;
int n;
int U[N], V[N];
int I[N], J[N], W[N];
template <const u64 P>
struct Calc {
  struct Num {
    u64 x;
    Num() {}
    Num(u64 x) : x(x) { ; }
    Num(int y) { x = y < 0 ? y + P : y; }
    Num& operator+=(const Num _) { return x += _.x, x >= P && (x -= P), *this; }
    Num& operator-=(const Num _) {
      return x -= _.x, i64(x) < 0 && (x += P), *this;
    }
    Num& operator*=(const Num _) { return x = (__int128)x * _.x % P, *this; }
    Num operator+(const Num _) const { return Num(x) += _; }
    Num operator-(const Num _) const { return Num(x) -= _; }
    Num operator*(const Num _) const { return Num(x) *= _; }
  } A[N][N];
  Num qpow(Num x) {
    i64 k = P - 2;
    Num res(1);
    for (; k; k >>= 1, x *= x)
      if (k & 1) res *= x;
    return res;
  }
  void Init() {
    for (int i = 1, iend = n; i <= iend; ++i) {
      for (int j = i, jend = n * 3; j <= jend; ++j)
        if (A[j][i].x > 0) {
          swap(A[i], A[j]);
          break;
        }
      Num Inv = qpow(A[i][i]);
      for (int j = i, jend = n * 3; j <= jend; ++j) A[i][j] *= Inv;
      for (int j = 1, jend = n; j <= jend; ++j)
        if (i != j && A[j][i].x)
          for (int k = n * 3, kend = i; k >= kend; --k)
            A[j][k] -= A[j][i] * A[i][k];
    }
  }
  Num S[N];
  void Evaluate() {
    for (int i = 1, iend = n; i <= iend; ++i) {
      S[i] = 0;
      for (int j = n + 1, jend = n * 3; j <= jend; ++j) S[i] += A[i][j] * W[j];
    }
  }
  i64 operator[](const int x) { return S[x].x; }
};
Calc<P1> X;
Calc<P2> Y;
void Add(int x, int y, int z) { X.A[x][y] += z, Y.A[x][y] += z; }
i64 P[N], Q[N];
char s[N];
int vis[N], mk[N];
void dfs(int u) {
  if (vis[u]) return;
  vis[u] = 1;
  dfs(s[u] == 'R' ? V[u] : U[u]);
}
int main() {
  n = rd() - 1;
  for (int i = 1, iend = n; i <= iend; ++i) {
    U[i] = rd(), V[i] = rd();
    Add(i, i, -2), Add(i, i + n, 1), Add(i, i + n * 2, -1);
    if (U[i] <= n) Add(U[i], i, 1), Add(U[i], i + n, -1);
    if (V[i] <= n) Add(V[i], i, 1);
  }
  X.Init(), Y.Init();
  for (int _ = 1, _end = rd(); _ <= _end; ++_) {
    int u = rd();
    scanf("%s", s + 1);
    for (int i = 1, iend = n * 3; i <= iend; ++i) W[i] = 0;
    W[1 + n * 2]++, W[u + n * 2]--;
    for (int i = 1, iend = n; i <= iend; ++i) W[i + n] = -(s[i] == 'R');
    X.Evaluate(), Y.Evaluate();
    int f = 1;
    for (int i = 1, iend = n; i <= iend; ++i) {
      memset(vis, 0, (n + 1) << 2);
      dfs(i);
      mk[i] = vis[u];
    }
    for (int i = 1, iend = n; i <= iend; ++i) {
      f &= X[i] == Y[i];
      f &= (X[i] == 0) || mk[i];
      f &= (X[i] + W[i + n] >= 0);
    }
    if (!f) {
      puts("-1");
      continue;
    }
    u64 ans = 0;
    for (int i = 1, iend = n; i <= iend; ++i) ans += X[i] * 2 + W[i + n];
    cout << ans << endl;
  }
}
