#include <bits/stdc++.h>
int t1, t2, t3;
char ch;
int n, q;
int lv[100005];
int up[100005][20];
int upmask[100005][20];
int lca(int u, int v) {
  if (lv[u] < lv[v]) std::swap(u, v);
  for (int i = 19; i >= 0; i--) {
    if (lv[u] - (1 << i) >= lv[v]) u = up[u][i];
  }
  for (int i = 19; i >= 0; i--) {
    if (up[u][i] != up[v][i]) {
      u = up[u][i];
      v = up[v][i];
    }
  }
  while (u != v) {
    u = up[u][0];
    v = up[v][0];
  }
  return u;
}
int pathmask(int u, int l) {
  int out = 0;
  for (int i = 19; i >= 0; i--) {
    if (lv[u] - (1 << i) >= l) {
      out |= upmask[u][i];
      u = up[u][i];
    }
  }
  return out;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &t1, &t2);
    if (t1 == -1) t1 = 0;
    if (t2 == -1)
      t2 = 3;
    else
      t2++;
    lv[i] = lv[t1] + 1;
    up[i][0] = t1;
    upmask[i][0] = t2;
    for (int j = 1; j < 20; j++) {
      up[i][j] = up[up[i][j - 1]][j - 1];
      upmask[i][j] = (upmask[up[i][j - 1]][j - 1] | upmask[i][j - 1]);
    }
  }
  scanf("%d", &q);
  while (q--) {
    scanf(" %c%d%d", &ch, &t1, &t2);
    t3 = lca(t1, t2);
    if (ch == '1') {
      if (t3 == t1 && pathmask(t2, lv[t3]) == 1) {
        printf("YES\n");
      } else
        printf("NO\n");
    } else if (t3 != 0 && pathmask(t2, lv[t3]) == 2 &&
               (t3 == t1 || pathmask(t1, lv[t3]) == 1)) {
      printf("YES\n");
    } else
      printf("NO\n");
  }
}
