#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int maxlog = 18;
int timer = 1;
int t_in[3][maxn];
int t_out[3][maxn];
int jump[maxn][maxlog];
vector<int> edges[3][maxn];
int h[maxn];
int parent[maxn];
int typ[maxn];
bool is_anc(int t, int u, int v) {
  return t_in[t][u] < t_in[t][v] && t_out[t][u] > t_out[t][v];
}
void dfs(int t, int v, int anc) {
  h[v] = anc == -1 ? 0 : h[anc] + 1;
  t_in[t][v] = timer++;
  if (t == 2) {
    jump[v][0] = anc;
    for (int j = (int)1; j <= (int)maxlog - 1; j++) {
      jump[v][j] = jump[v][j - 1] == -1 ? -1 : jump[jump[v][j - 1]][j - 1];
    }
  }
  for (int u : edges[t][v]) {
    dfs(t, u, v);
  }
  t_out[t][v] = timer++;
}
int up(int x, int delta) {
  for (int j = maxlog - 1; j >= 0; j--)
    if (delta & (1 << j)) x = jump[x][j];
  return x;
}
int lca(int x, int y) {
  if (h[x] > h[y]) swap(x, y);
  y = up(y, h[y] - h[x]);
  if (x == y) return x;
  for (int j = maxlog - 1; j >= 0; j--) {
    int x1 = jump[x][j];
    int y1 = jump[y][j];
    if (x1 != y1) {
      x = x1;
      y = y1;
    }
  }
  return jump[x][0];
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (int)1; i <= (int)n; i++) {
    scanf("%d%d", &parent[i], &typ[i]);
    if (typ[i] != -1) {
      edges[typ[i]][parent[i]].push_back(i);
      edges[2][parent[i]].push_back(i);
    }
  }
  for (int t = 0; t < (int)3; t++)
    for (int i = (int)1; i <= (int)n; i++)
      if (t_in[t][i] == 0) dfs(t, i, -1);
  int queries;
  scanf("%d", &queries);
  for (int q = 0; q < (int)queries; q++) {
    int q_typ, u, v;
    scanf("%d%d%d", &q_typ, &u, &v);
    bool res;
    if (q_typ == 1) {
      res = is_anc(0, u, v);
    } else {
      if (typ[v] <= 0)
        res = false;
      else if (typ[u] != 0)
        res = is_anc(1, u, v);
      else {
        int l = lca(u, v);
        res = l != -1 && (l == u || is_anc(0, l, u)) && is_anc(1, l, v);
      }
    }
    printf(res ? "YES\n" : "NO\n");
  }
}
