#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, fa[17 + 1][100000 + 5], c[17 + 1][100000 + 5], dep[100000 + 5],
    s[100000 + 5];
inline int getfa(int x) { return s[x] ? s[x] = getfa(s[x]) : x; }
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int k = dep[x] - dep[y], j = 0; k; k >>= 1, ++j)
    if (k & 1) x = fa[j][x];
  if (x == y) return x;
  for (int i = 17; ~i; --i)
    if (fa[i][x] != fa[i][y]) x = fa[i][x], y = fa[i][y];
  return fa[0][x];
}
pair<int, int> Solve(int x, int y) {
  int res1 = 0, res2 = 0;
  if (dep[x] < dep[y]) {
    for (int k = dep[y] - dep[x], j = 0; k; k >>= 1, ++j)
      if (k & 1) res2 |= c[j][y], y = fa[j][y];
  } else {
    for (int k = dep[x] - dep[y], j = 0; k; k >>= 1, ++j)
      if (k & 1) res1 |= c[j][x], x = fa[j][x];
  }
  if (x == y) return make_pair(res1, res2);
  for (int i = 17; ~i; --i)
    if (fa[i][x] != fa[i][y])
      res1 |= c[i][x], res2 |= c[i][y], x = fa[i][x], y = fa[i][y];
  return make_pair(res1 | c[0][x], res2 | c[0][y]);
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) {
    int p = read(), t = read();
    if (p == -1) continue;
    if (getfa(i) != getfa(p)) s[getfa(i)] = getfa(p);
    dep[i] = dep[p] + 1;
    fa[0][i] = p;
    c[0][i] = t + 1;
  }
  for (int i = 1; i <= 17; ++i)
    for (int j = 1; j <= n; ++j)
      fa[i][j] = fa[i - 1][fa[i - 1][j]],
      c[i][j] = c[i - 1][j] | c[i - 1][fa[i - 1][j]];
  for (int Q = read(); Q; --Q) {
    int op = read(), x = read(), y = read();
    if (x == y || getfa(x) != getfa(y)) {
      puts("NO");
      continue;
    }
    if (op == 1) {
      if (lca(x, y) != x) {
        puts("NO");
        continue;
      }
      if (Solve(x, y).second == 1)
        puts("YES");
      else
        puts("NO");
      continue;
    }
    pair<int, int> res = Solve(x, y);
    puts(((!(res.first & 2)) && res.second == 2) ? "YES" : "NO");
  }
  return 0;
}
