#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;
const int MAXL = 21;
struct eT {
  void setd(int _u, int _v, int _l) { u = _u, v = _v, last = _l; }
  int u, v, last;
} edge[MAXN];
int n, q;
int ke, la[MAXN];
int fa[MAXN], tp[MAXN], lev[MAXN];
int lca[MAXN][MAXL], ct[MAXN][MAXL];
int qtp, qu, qv;
void init();
void input();
void inputq();
void work();
void dfs(int now, int nl);
int getlca(int u, int v);
int getcc(int u, int v);
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d%d", &fa[i], &tp[i]);
  scanf("%d", &q);
}
void inputq() { scanf("%d%d%d", &qtp, &qu, &qv); }
void work() {
  ke = 0;
  memset(la, -1, sizeof(la));
  for (int i = 1; i <= n; ++i) {
    if (~fa[i]) {
      edge[ke].setd(fa[i], i, la[fa[i]]);
      la[fa[i]] = ke++;
    }
  }
  for (int i = 1; i <= n; ++i)
    if (fa[i] == -1) dfs(i, 1);
  memset(lca, -1, sizeof(lca));
  for (int i = 1; i <= n; ++i)
    if (~fa[i]) lca[i][0] = fa[i], ct[i][0] = tp[i];
  for (int j = 1; j < MAXL; ++j)
    for (int i = 1; i <= n; ++i)
      if (~lca[i][j - 1])
        lca[i][j] = lca[lca[i][j - 1]][j - 1],
        ct[i][j] = ct[i][j - 1] + ct[lca[i][j - 1]][j - 1];
  int ng;
  for (int i = 0; i < q; ++i) {
    inputq();
    ng = getlca(qu, qv);
    if (ng == -1 || qu == qv) {
      printf("NO\n");
      continue;
    }
    if (qtp == 1) {
      if ((ng == qu) && (getcc(qv, ng) == 0)) {
        printf("YES\n");
      } else {
        printf("NO\n");
      }
    } else {
      if ((getcc(qu, ng) == 0) && (getcc(qv, ng) == lev[qv] - lev[ng]) &&
          (ng ^ qv)) {
        printf("YES\n");
      } else {
        printf("NO\n");
      }
    }
  }
}
void dfs(int now, int nl) {
  lev[now] = nl;
  for (int i = la[now]; ~i; i = edge[i].last) dfs(edge[i].v, nl + 1);
}
int getlca(int u, int v) {
  if (lev[u] < lev[v]) swap(u, v);
  int d = lev[u] - lev[v], b = 0;
  while (d) {
    if (d & 1) u = lca[u][b];
    d >>= 1;
    ++b;
  }
  if (u == v) return u;
  for (int i = MAXL - 1; i >= 0; --i) {
    if (lca[u][i] ^ lca[v][i]) u = lca[u][i], v = lca[v][i];
  }
  return lca[u][0];
}
int getcc(int u, int v) {
  int d = lev[u] - lev[v], ans = 0;
  for (int i = 0; i < MAXL; ++i) {
    if (d >> i & 1) ans += ct[u][i], u = lca[u][i];
  }
  return ans;
}
