#include <bits/stdc++.h>
using namespace std;
const int N = 100002;
int n, q, p[N], t[N], parent[N], sum[N];
vector<vector<int> > g(N);
int T[N], P[N][18], L[N];
bool vis[N];
int find(int a) { return a == parent[a] ? a : parent[a] = find(parent[a]); }
void merge(int a, int b) {
  a = find(a), b = find(b);
  if (a != b) parent[a] = b;
}
void dfs(int x, int level) {
  vis[x] = true;
  for (int i = 0; i <= ((int)(g[x]).size()) - 1; ++i) {
    int child = g[x][i];
    if (!vis[child]) {
      sum[child] = sum[x] + t[child];
      T[child] = x;
      L[child] = level + 1;
      dfs(child, level + 1);
    }
  }
}
void build() {
  for (int root = 1; root <= n; ++root)
    if (p[root] == -1) {
      T[root] = root;
      L[root] = 1;
      dfs(root, 1);
    }
  for (int i = 1; i <= n; ++i)
    for (int j = 0; (1ll << j) < n; j++) P[i][j] = -1;
  for (int i = 1; i <= n; ++i) P[i][0] = T[i];
  for (int j = 1; (1ll << j) < n; j++)
    for (int i = 1; i <= n; ++i)
      if (P[i][j - 1] != -1) P[i][j] = P[P[i][j - 1]][j - 1];
}
int query(int p, int q) {
  if (L[p] < L[q]) swap(p, q);
  int log;
  for (log = 1; (1ll << log) <= L[p]; log++)
    ;
  log--;
  for (int i = log; i >= 0; --i)
    if (L[p] - (1ll << i) >= L[q]) p = P[p][i];
  if (p == q) return p;
  for (int i = log; i >= 0; i--)
    if (P[p][i] != -1 && P[p][i] != P[q][i]) p = P[p][i], q = P[q][i];
  return T[p];
}
bool isSpecial(int x, int y) {
  if (find(x) != find(y) or x == y or x != query(x, y)) return false;
  return sum[y] - sum[x] == 0;
}
bool isPart(int x, int y) {
  if (find(x) != find(y) or x == y) return false;
  int z = query(x, y);
  return z != y and (x == z or isSpecial(z, x)) and
         sum[y] - sum[z] == L[y] - L[z];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    parent[i] = i;
    scanf("%d%d", &p[i], &t[i]);
  }
  for (int i = 1; i <= n; ++i)
    if (~p[i]) merge(i, p[i]), g[p[i]].push_back(i);
  build();
  scanf("%d", &q);
  while (q--) {
    int k, x, y;
    scanf("%d%d%d", &k, &x, &y);
    if (k == 1)
      printf("%s\n", isSpecial(x, y) ? "YES" : "NO");
    else
      printf("%s\n", isPart(x, y) ? "YES" : "NO");
  }
}
