#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g[100100];
int fa[100100][18], typ[100100], n;
int sum[100100][2], dep[100100];
void dfs(int u) {
  for (int i = 1; i < 18; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  for (auto v : g[u]) {
    int A = v.first, tp = v.second;
    sum[A][0] = sum[u][0];
    sum[A][1] = sum[u][1];
    ++sum[A][tp];
    dep[A] = dep[u] + 1;
    dfs(A);
  }
}
int LCA(int u, int v) {
  if (dep[u] > dep[v]) swap(u, v);
  int hu = dep[u], hv = dep[v];
  int tu = u, tv = v;
  for (int det = hv - hu, i = 0; det; det >>= 1, i++)
    if (det & 1) tv = fa[tv][i];
  if (tu == tv) return tu;
  for (int i = 17; i >= 0; --i) {
    if (fa[tu][i] == fa[tv][i]) continue;
    tu = fa[tu][i];
    tv = fa[tv][i];
  }
  return fa[tu][0];
}
int tmp[2];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &fa[i][0], &typ[i]);
    if (fa[i][0] == -1) fa[i][0] = typ[i] = 0;
  }
  for (int i = 1; i <= n; ++i) g[fa[i][0]].push_back(pair<int, int>(i, typ[i]));
  dfs(0);
  int q;
  scanf("%d", &q);
  while (q--) {
    int tp, u, v;
    scanf("%d%d%d", &tp, &u, &v);
    int lca = LCA(u, v);
    if (!lca || lca == v) {
      puts("NO");
      continue;
    }
    if (tp == 1) {
      if (lca != u) {
        puts("NO");
        continue;
      }
      tmp[0] = sum[v][0] - sum[u][0];
      tmp[1] = sum[v][1] - sum[u][1];
      if (tmp[1]) {
        puts("NO");
        continue;
      }
      puts("YES");
    } else {
      tmp[0] = sum[u][0] - sum[lca][0];
      tmp[1] = sum[u][1] - sum[lca][1];
      if (tmp[1]) {
        puts("NO");
        continue;
      }
      tmp[0] = sum[v][0] - sum[lca][0];
      tmp[1] = sum[v][1] - sum[lca][1];
      if (tmp[0]) {
        puts("NO");
        continue;
      }
      puts("YES");
    }
  }
  return 0;
}
