#include <bits/stdc++.h>
using namespace std;
int par[100050];
vector<int> chi[100500];
vector<int> chi2[100500];
vector<int> chi3;
vector<vector<int> > up;
int bigpart[100500];
int n, l;
vector<int> tin4, tout4;
int timer4 = 10;
void dfs4(int v, int p, int pp) {
  tin4[v] = ++timer4;
  up[v][0] = pp;
  for (int i = 1; i <= l; ++i) up[v][i] = up[up[v][i - 1]][i - 1];
  for (int i = 0; i <= l; i++) {
  }
  for (auto vv : chi[v]) {
    dfs4(vv, p, v);
  }
  for (auto vv : chi2[v]) {
    dfs4(vv, p, v);
  }
  if (!v) {
    for (auto vv : chi3) {
      dfs4(vv, p, v);
    }
  }
  tout4[v] = ++timer4;
}
bool upper4(int a, int b) { return tin4[a] <= tin4[b] && tout4[a] >= tout4[b]; }
int lca(int a, int b) {
  if (upper4(a, b)) return a;
  if (upper4(b, a)) return b;
  for (int i = l; i >= 0; --i)
    if (!upper4(up[a][i], b)) a = up[a][i];
  return up[a][0];
}
char wh[100500];
char clr[100500];
char clr2[100500];
int timer = 10;
int tin[100500];
int tout[100500];
int timer2 = 10;
int tin2[100500];
int tout2[100500];
void dfs(int u) {
  clr[u] = 1;
  tin[u] = ++timer;
  for (auto v : chi[u]) {
    dfs(v);
  }
  tout[u] = ++timer;
}
void dfs2(int u, int ro) {
  clr2[u] = 1;
  bigpart[u] = ro;
  tin2[u] = ++timer2;
  for (auto v : chi2[u]) {
    dfs2(v, ro);
  }
  tout2[u] = ++timer2;
}
bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
bool upper2(int a, int b) { return tin2[a] <= tin2[b] && tout2[a] >= tout2[b]; }
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int pa, typ;
    cin >> pa >> typ;
    if (pa == -1) {
      par[i] = 0;
      wh[i] = 'r';
      chi3.push_back(i);
      continue;
    }
    if (typ) {
      par[i] = pa;
      wh[i] = 'p';
      chi2[pa].push_back(i);
    } else {
      par[i] = pa;
      chi[pa].push_back(i);
      wh[i] = 's';
    }
  }
  for (int i = 0; i <= n; i++) {
    if (!clr[i]) {
      dfs(i);
    }
    if (!clr2[i]) {
      dfs2(i, i);
    }
  }
  l = 1;
  tin4.resize(n + 2), tout4.resize(n + 2), up.resize(n + 2);
  while ((1 << l) <= n + 1) ++l;
  for (int i = 0; i <= n; ++i) up[i].resize(l + 1);
  dfs4(0, 0, 0);
  int q;
  cin >> q;
  while (q--) {
    int typ, u, v;
    cin >> typ >> u >> v;
    if (typ == 1) {
      if (wh[v] == 'p' || wh[v] == 'r') {
        cout << "NO" << endl;
        continue;
      }
      if (u != v && upper(u, v)) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    } else {
      if (u == v) {
        cout << "NO" << endl;
        continue;
      }
      if (wh[v] == 'r' || wh[v] == 's') {
        cout << "NO" << endl;
        continue;
      }
      if (u != v && upper2(u, v)) {
        cout << "YES" << endl;
        continue;
      }
      int w = lca(u, v);
      if (w != v && upper(w, u) && upper2(w, v)) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    }
  }
  return 0;
}
