#include <bits/stdc++.h>
using namespace std;
const int N = 100003;
int n, m;
int cnt, head[N];
struct Edge {
  int nxt, to, w;
} e[N << 1];
int tot, dep[N], c[N], f[N][23], Max[N][23], Min[N][23];
bool v[N];
void add(int u, int v, int w) {
  e[++cnt] = (Edge){head[u], v, w}, head[u] = cnt;
}
void dfs(int x) {
  v[x] = true;
  for (int i = 1; i <= 20; i++) {
    f[x][i] = f[f[x][i - 1]][i - 1];
    Max[x][i] = max(Max[x][i - 1], Max[f[x][i - 1]][i - 1]);
    Min[x][i] = min(Min[x][i - 1], Min[f[x][i - 1]][i - 1]);
  }
  for (int i = head[x]; i; i = e[i].nxt) {
    int to = e[i].to;
    c[to] = c[x], dep[to] = dep[x] + 1;
    f[to][0] = x, Max[to][0] = Min[to][0] = e[i].w;
    dfs(to);
  }
}
int lca(int x, int y) {
  if (c[x] != c[y]) return 0;
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 20; i >= 0; i--)
    if (dep[f[x][i]] >= dep[y]) x = f[x][i];
  if (x == y) return x;
  for (int i = 20; i >= 0; i--)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  return f[x][0];
}
int getmax(int x, int y) {
  for (int i = 20; i >= 0; i--)
    if (dep[f[x][i]] >= dep[y]) {
      if (Max[x][i]) return 1;
      x = f[x][i];
    }
  return 0;
}
int getmin(int x, int y) {
  for (int i = 20; i >= 0; i--)
    if (dep[f[x][i]] >= dep[y]) {
      if (Min[x][i] == 0) return 0;
      x = f[x][i];
    }
  return 1;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x, tp;
    scanf("%d%d", &x, &tp);
    if (tp != -1) add(x, i, tp);
  }
  for (int i = 1; i <= n; i++)
    if (!v[i]) c[i] = ++tot, dep[i] = 1, dfs(i);
  scanf("%d", &m);
  while (m--) {
    int o, x, y;
    scanf("%d%d%d", &o, &x, &y);
    int z = lca(x, y);
    if (o == 1) {
      if (x != y && z == x && getmax(y, z) == 0)
        puts("YES");
      else
        puts("NO");
    } else {
      if (z && y != z && getmax(x, z) == 0 && getmin(y, z))
        puts("YES");
      else
        puts("NO");
    }
  }
  return 0;
}
