#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, q;
int p[maxn], t[maxn], h[maxn];
int b[maxn][20], l[2][maxn][20];
int lca(int u, int v) {
  for (int i = 19; i >= 0; i--)
    if (h[b[u][i]] >= h[v]) u = b[u][i];
  for (int i = 19; i >= 0; i--)
    if (h[b[v][i]] >= h[u]) v = b[v][i];
  if (u == v) return u;
  for (int i = 19; i >= 0; i--)
    if (b[u][i] != b[v][i]) {
      u = b[u][i];
      v = b[v][i];
    }
  return p[v];
}
bool get(int t, int u, int v) {
  bool re = true;
  for (int i = 19; i >= 0; i--)
    if (h[b[u][i]] >= h[v]) {
      if (l[t][u][i] == 0) re = false;
      u = b[u][i];
    }
  return re;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &p[i], &t[i]);
    if (p[i] != -1) {
      h[i] = h[p[i]] + 1;
      b[i][0] = p[i];
      l[t[i]][i][0] = 1;
    } else
      h[i] = 1;
  }
  for (int i = 1; i < 20; i++)
    for (int j = 1; j <= n; j++) {
      b[j][i] = b[b[j][i - 1]][i - 1];
      if (l[0][j][i - 1] == 1 && l[0][b[j][i - 1]][i - 1] == 1) l[0][j][i] = 1;
      if (l[1][j][i - 1] == 1 && l[1][b[j][i - 1]][i - 1] == 1) l[1][j][i] = 1;
    }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int k, u, v;
    scanf("%d %d %d", &k, &u, &v);
    if (k == 1) {
      if (lca(u, v) == u && get(0, v, u) && u != v)
        printf("YES\n");
      else
        printf("NO\n");
    } else {
      if (lca(u, v) != 0 && get(0, u, lca(u, v)) && get(1, v, lca(u, v)) &&
          u != v && v != lca(u, v))
        printf("YES\n");
      else
        printf("NO\n");
    }
  }
  return 0;
}
