#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<pair<int, int> > g[N];
vector<int> root;
int dp[19][N], d[N], cum1[N], cum2[N];
void dfs(int u, int p, int dep, int ca, int cb, int e) {
  d[u] = dep;
  if (e == 0)
    ca++;
  else if (e == 1)
    cb++;
  cum1[u] = ca, cum2[u] = cb;
  for (int i = 0; i < g[u].size(); i++) {
    int v = g[u][i].first;
    if (v != p) {
      dfs(v, u, dep + 1, ca, cb, g[u][i].second);
    }
  }
  if (e == 0)
    ca--;
  else if (e == 1)
    cb--;
}
int lca(int a, int b) {
  if (d[a] < d[b]) swap(a, b);
  int l = 0;
  while ((1 << l) <= d[a]) ++l;
  --l;
  for (int i = l; i >= 0; --i)
    if (d[a] - (1 << i) >= d[b]) a = dp[i][a];
  if (a == b) return a;
  for (int i = l; i >= 0; --i)
    if (dp[i][a] != dp[i][b]) {
      a = dp[i][a];
      b = dp[i][b];
    }
  return dp[0][a];
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0, p, t; i < n; i++) {
    scanf("%d%d", &p, &t);
    dp[0][i] = -1;
    if (p == -1) {
      root.push_back(i);
    } else {
      p--;
      dp[0][i] = p;
      g[p].push_back({i, t});
    }
  }
  for (int i = 0; i < root.size(); i++) dfs(root[i], -1, 0, 0, 0, -1);
  for (int i = 1; i < 19; i++) {
    for (int j = 0; j < n; j++) {
      if (dp[i - 1][j] == -1)
        dp[i][j] = -1;
      else
        dp[i][j] = dp[i - 1][dp[i - 1][j]];
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int t, a, b;
    scanf("%d%d%d", &t, &a, &b);
    a--, b--;
    int c = lca(a, b);
    if (a == b || c == -1 || c == b) {
      puts("NO");
      continue;
    }
    if (t == 1) {
      int temp = cum1[b] - cum1[c];
      if (c == a && temp == d[b] - d[a])
        puts("YES");
      else
        puts("NO");
    } else {
      if (c == a) {
        if (cum2[b] - cum2[c] == d[b] - d[a])
          puts("YES");
        else
          puts("NO");
        continue;
      }
      int cm1 = cum1[a] - cum1[c];
      int cm2 = cum2[b] - cum2[c];
      if (cm1 == d[a] - d[c] && cm2 == d[b] - d[c])
        puts("YES");
      else
        puts("NO");
    }
  }
  return 0;
}
