#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g[100005];
int grp[100005], idx;
int P[17][100005], h[100005];
int second[100005];
void dfs(int node, int d = 1, int sum = 0) {
  h[node] = d;
  grp[node] = idx;
  second[node] = sum;
  for (auto p : g[node]) {
    dfs(p.first, d + 1, sum + p.second);
  }
}
int query(int p, int q) {
  int log;
  if (h[p] < h[q]) swap(p, q);
  for (log = 1; (1 << log) <= h[p]; log++)
    ;
  log--;
  for (int i = log; i >= 0; i--)
    if (h[p] - (1 << i) >= h[q]) p = P[i][p];
  if (p == q) return p;
  for (int i = log; i >= 0; i--)
    if (P[i][p] != -1 && P[i][p] != P[i][q]) p = P[i][p], q = P[i][q];
  return P[0][p];
}
void no() { printf("NO\n"); }
void yes() { printf("YES\n"); }
int main() {
  int n, c, x, y, q;
  cin >> n;
  memset(P, -1, sizeof(P));
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &x, &y);
    if (x == -1) {
      continue;
    }
    x--;
    g[x].push_back(make_pair(i, y));
    P[0][i] = x;
  }
  for (int i = 0; i < n; i++) {
    if (grp[i]) continue;
    idx++;
    dfs(i);
  }
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i <= n; i++)
      if (P[j - 1][i] != -1) P[j][i] = P[j - 1][P[j - 1][i]];
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d %d", &c, &y, &x);
    x--, y--;
    if (grp[x] != grp[y] || x == y) {
      no();
      continue;
    }
    if (c == 1) {
      int lca = query(x, y);
      if (lca != y) {
        no();
      } else if (second[x] - second[y] != 0) {
        no();
      } else
        yes();
    } else {
      int lca = query(x, y);
      if (lca == x) {
        no();
      } else if (lca == y) {
        if (second[x] - second[y] != h[x] - h[y]) {
          no();
        } else
          yes();
      } else {
        if (second[x] - second[lca] == h[x] - h[lca]) {
          if (second[y] - second[lca] == 0) {
            yes();
          } else
            no();
        } else
          no();
      }
    }
  }
  return 0;
}
