#include <bits/stdc++.h>
using namespace std;
int depth[200009], par[200009][21], special_count[200009], part_count[200009],
    n;
vector<int> g[200009], g1[200009];
int comp = 1, comp_no[200009];
inline void dfs(int pos, int prev, int val) {
  comp_no[pos] = comp;
  depth[pos] = depth[prev] + 1;
  special_count[pos] = special_count[prev];
  part_count[pos] = part_count[prev];
  par[pos][0] = prev;
  if (val == 0) {
    special_count[pos]++;
  } else if (val == 1) {
    part_count[pos]++;
  }
  for (int i = 0; i < g[pos].size(); i++) {
    if (g[pos][i] != prev) {
      dfs(g[pos][i], pos, g1[pos][i]);
    }
  }
}
inline int lca(int x, int y) {
  if (depth[x] < depth[y]) {
    swap(x, y);
  }
  int diff = depth[x] - depth[y];
  for (int i = 0; i <= 19; i++) {
    if (diff & (1 << i)) {
      x = par[x][i];
    }
  }
  if (x == y) {
    return x;
  }
  for (int i = 19; i >= 0; i--) {
    if (par[x][i] != par[y][i]) {
      x = par[x][i];
      y = par[y][i];
    }
  }
  return par[x][0];
}
inline void precomp() {
  for (int j = 1; j <= 19; j++) {
    for (int i = 1; i <= n; i++) {
      par[i][j] = par[par[i][j - 1]][j - 1];
    }
  }
}
inline int get_special(int u, int v) {
  return special_count[u] - special_count[v];
}
inline int get_part(int u, int v) { return part_count[u] - part_count[v]; }
vector<int> to_dfs;
int main() {
  scanf("%d", &n);
  int parent[n + 1];
  int type[n + 1];
  memset(comp_no, -1, sizeof(comp_no));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &parent[i]);
    scanf("%d", &type[i]);
    if ((parent[i] == -1) && (type[i] == -1)) {
      to_dfs.push_back(i);
      continue;
    }
    g[i].push_back(parent[i]);
    g[parent[i]].push_back(i);
    g1[parent[i]].push_back(type[i]);
    g1[i].push_back(type[i]);
  }
  for (int i = 0; i < to_dfs.size(); i++) {
    dfs(to_dfs[i], 0, -1);
    comp++;
  }
  precomp();
  int q;
  scanf("%d", &q);
  int cnt = 1;
  while (q--) {
    int t;
    scanf("%d", &t);
    int u, v;
    scanf("%d", &u);
    scanf("%d", &v);
    if (u == v) {
      printf("NO\n");
      continue;
    }
    if (comp_no[u] != comp_no[v]) {
      printf("NO\n");
      continue;
    }
    int z = lca(u, v);
    if (t == 1) {
      if (z != u) {
        printf("NO\n");
        continue;
      }
      int ans = get_special(v, u);
      if (ans == depth[v] - depth[u]) {
        printf("YES\n");
        continue;
      } else {
        printf("NO\n");
        continue;
      }
    } else {
      int z = lca(v, u);
      if (z == v) {
        printf("NO\n");
        continue;
      }
      int ans = get_part(v, z);
      if (ans == depth[v] - depth[z]) {
        ans = get_special(u, z);
        if (ans == depth[u] - depth[z]) {
          printf("YES\n");
          continue;
        } else {
          printf("NO\n");
          continue;
        }
      } else {
        printf("NO\n");
        continue;
      }
    }
    cnt++;
  }
  return 0;
}
