#include <bits/stdc++.h>
using namespace std;
const int MXN = 100005;
int dep[MXN];
int anc[MXN][17];
int cnt[MXN][17][2];
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int diff = dep[x] - dep[y];
  for (int i = 16; ~i; --i) {
    if (diff >> i & 1) x = anc[x][i];
  }
  if (x == y) return x;
  for (int i = 16; ~i; --i) {
    if (anc[x][i] != anc[y][i]) {
      x = anc[x][i];
      y = anc[y][i];
    }
  }
  return anc[x][0];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int p, t;
    cin >> p >> t;
    if (t == -1) continue;
    dep[i] = dep[p] + 1;
    anc[i][0] = p;
    cnt[i][0][t] = 1;
    for (int j = 0; j < 16; ++j) {
      anc[i][j + 1] = anc[anc[i][j]][j];
      cnt[i][j + 1][0] = cnt[i][j][0] + cnt[anc[i][j]][j][0];
      cnt[i][j + 1][1] = cnt[i][j][1] + cnt[anc[i][j]][j][1];
    }
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int t, x, y;
    cin >> t >> x >> y;
    int lcanc = lca(x, y);
    if (lcanc == 0 || lcanc == y) {
      cout << "NO\n";
      continue;
    }
    if (lcanc == x) {
      int sum = 0;
      int diff = dep[y] - dep[x];
      for (int i = 16; ~i; --i) {
        if (diff >> i & 1) {
          sum += cnt[y][i][t - 1];
          y = anc[y][i];
        }
      }
      if (sum == diff) {
        cout << "YES\n";
      } else {
        cout << "NO\n";
      }
    } else if (t == 2) {
      int sumx = 0;
      int sumy = 0;
      int dx = dep[x] - dep[lcanc];
      int dy = dep[y] - dep[lcanc];
      for (int i = 16; ~i; --i) {
        if (dx >> i & 1) sumx += cnt[x][i][0], x = anc[x][i];
        if (dy >> i & 1) sumy += cnt[y][i][1], y = anc[y][i];
      }
      if (sumx == dx && sumy == dy) {
        cout << "YES\n";
      } else {
        cout << "NO\n";
      }
    } else {
      cout << "NO\n";
    }
  }
}
