#include <bits/stdc++.h>
using namespace std;
int n, q, parent[100000], xtype[100000], ace[100000][2];
vector<int> edges[100000];
vector<pair<int, int>> queries[100000];
array<int, 3> querx[100000];
struct DSU {
  int n, *parex, *rankx;
  unordered_map<int, vector<int>> roots;
  vector<int> vi;
  DSU(int n) : n(n) {
    parex = (int *)malloc(n * sizeof(int));
    rankx = (int *)malloc(n * sizeof(int));
    for (int i = 0; i < n; i++) parex[i] = i, rankx[i] = 0;
  }
  ~DSU() { free(parex), free(rankx); }
  int findx(int x) {
    if (parex[x] != x) parex[x] = findx(parex[x]);
    return parex[x];
  }
  void unionx(int x, int y) {
    x = findx(x);
    y = findx(y);
    if (x == y)
      return;
    else if (rankx[x] < rankx[y])
      parex[x] = y;
    else if (rankx[x] > rankx[y])
      parex[y] = x;
    else
      parex[y] = x, rankx[x]++;
  }
  void post() {
    roots.clear();
    for (int i = 0; i < n; i++) {
      int j = findx(i);
      if (roots.count(j) == 0)
        roots[j] = vi, roots[j].push_back(j);
      else
        roots[j].push_back(i);
    }
  }
};
struct LCA {
  DSU *dsu;
  int *ancex, *lca, *colox;
  LCA(DSU *dsu, int n, int q) : dsu(dsu) {
    ancex = (int *)malloc(n * sizeof(int));
    colox = (int *)malloc(n * sizeof(int));
    lca = (int *)malloc(q * sizeof(int));
    memset(colox, -1, n * sizeof(int));
    memset(lca, -1, q * sizeof(int));
    for (int i = 0, it = 0; i < n; i++)
      if (parent[i] == -1) run(it++, i);
  }
  ~LCA() { free(ancex), free(colox), free(lca); }
  void run(int it, int u) {
    ancex[u] = u;
    for (auto v : edges[u]) {
      run(it, v);
      dsu->unionx(u, v);
      ancex[dsu->findx(u)] = u;
    }
    colox[u] = it;
    for (auto &qr : queries[u])
      if (colox[qr.first] == it) lca[qr.second] = ancex[dsu->findx(qr.first)];
  }
};
int runace(int t, int i) {
  if (ace[i][t] != -1)
    return ace[i][t];
  else if (parent[i] == -1 || xtype[i] != t)
    return ace[i][t] = i;
  else
    return ace[i][t] = runace(t, parent[i]);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> parent[i] >> xtype[i];
    if (parent[i] != -1) edges[--parent[i]].push_back(i);
  }
  cin >> q;
  int a, b, t;
  for (int i = 0; i < q; i++) {
    cin >> t >> a >> b, a--, b--;
    queries[a].push_back(make_pair(b, i));
    queries[b].push_back(make_pair(a, i));
    querx[i] = {a, b, t - 1};
  }
  memset(ace, -1, sizeof(ace));
  for (int i = 0; i < n; i++) runace(0, i), runace(1, i);
  DSU dsu(n);
  LCA lca(&dsu, n, q);
  for (int i = 0; i < q; i++) {
    a = querx[i][0], b = querx[i][1], t = querx[i][2];
    if (t == 0) {
      if (a == lca.lca[i] && ace[b][0] <= lca.lca[i] && a != b)
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    } else {
      if (lca.lca[i] != -1 && b != lca.lca[i] && a != b &&
          ace[a][0] <= lca.lca[i] && ace[b][1] <= lca.lca[i])
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  }
  return 0;
}
