#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct edge {
  int nxt, to;
} e[N];
int fir[N], cnt = 0;
int fa[N], st[N][17], dep[N], wei[N], bel[N], cur = 0;
bool no_fa[N];
pair<int, int> rec[N];
inline int getf(int x) { return fa[x] == x ? x : fa[x] = getf(fa[x]); }
inline void add(int x, int y) {
  e[++cnt] = (edge){fir[x], y};
  fir[x] = cnt;
}
inline void dfs(int x, int fa) {
  bel[x] = cur;
  dep[x] = dep[fa] + 1;
  wei[x] += wei[fa];
  st[x][0] = fa;
  for (register short i = 1; i <= 16; i++) st[x][i] = st[st[x][i - 1]][i - 1];
  for (register int i = fir[x]; i; i = e[i].nxt)
    if (e[i].to != fa) dfs(e[i].to, x);
}
inline int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (register short i = 16; i >= 0 && dep[x] != dep[y]; i--)
    if (dep[st[x][i]] >= dep[y]) x = st[x][i];
  if (x == y) return x;
  for (register short i = 16; i >= 0 && st[x][0] != st[y][0]; i--)
    if (st[x][i] != st[y][i]) {
      x = st[x][i];
      y = st[y][i];
    }
  return st[x][0];
}
int main() {
  int n, f, type, q, u, v, lca;
  scanf("%d", &n);
  for (register int i = 1; i <= n; i++) fa[i] = i;
  for (register int i = 1; i <= n; i++) {
    scanf("%d%d", &f, &type);
    if (f == -1) {
      no_fa[i] = 1;
      continue;
    }
    add(f, i);
    wei[i] = type;
  }
  for (register int i = 1; i <= n; i++)
    if (no_fa[i]) {
      cur++;
      dfs(i, 0);
    }
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d%d", &type, &u, &v);
    if (u == v || bel[u] != bel[v]) {
      puts("NO");
      continue;
    }
    lca = LCA(u, v);
    if (type == 1) {
      if (u == lca && wei[u] == wei[v])
        puts("YES");
      else
        puts("NO");
    } else {
      if (v != lca && wei[u] - wei[lca] == 0 &&
          wei[v] - wei[lca] == dep[v] - dep[lca])
        puts("YES");
      else
        puts("NO");
    }
  }
  return 0;
}
