#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T qmin(const T &a, const T &b) {
  return a < b ? a : b;
}
template <typename T>
inline T qmax(const T &a, const T &b) {
  return a > b ? a : b;
}
template <typename T>
inline void getmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <typename T>
inline void getmax(T &a, const T &b) {
  if (a < b) a = b;
}
inline void fileio(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
const int inf = (int)1e9 + 7;
const long long linf = (long long)1e17 + 7;
const int N = 1e5 + 7, M = N << 1, logN = 21;
int v[M], nxt[M];
int head[N];
int p0[N][logN], p1[N][logN];
int dep[N], n;
inline void addedge(int p, int x, int y) {
  v[p] = y, nxt[p] = head[x], head[x] = p;
}
inline void dfs(int u, int p) {
  dep[u] = dep[p] + 1;
  for (int e = head[u]; e; e = nxt[e]) dfs(v[e], u);
}
inline int goup(int par[][logN], int u, int d) {
  if (d < 0) return 0;
  for (register int i = 0; i < (logN); ++i)
    if (d >> i & 1) {
      u = par[u][i];
    }
  return u;
}
inline bool check(int u, int v) {
  if (u == v) return false;
  int pu = u, pv = v;
  for (register int i = (logN)-1; i >= 0; --i)
    if (p0[pu][i]) pu = p0[pu][i];
  for (register int i = (logN)-1; i >= 0; --i)
    if (p1[pv][i]) pv = p1[pv][i];
  int lca = (dep[pu] >= dep[pv] ? pu : pv);
  if (goup(p0, u, dep[u] - dep[lca]) != lca ||
      goup(p1, v, dep[v] - dep[lca]) != lca || lca == v)
    return false;
  return true;
}
int main() {
  scanf("%d", &n);
  for (register int i = (1); i <= (n); ++i) {
    int p, tp;
    scanf("%d%d", &p, &tp);
    if (p == -1) continue;
    addedge(i, p, i);
    if (tp == 0) {
      p0[i][0] = p;
    } else if (tp == 1) {
      p1[i][0] = p;
    } else
      assert(false);
  }
  for (register int i = (1); i <= (n); ++i)
    if (!dep[i]) dfs(i, 0);
  for (register int i = (1); i <= (logN - 1); ++i) {
    for (register int j = (1); j <= (n); ++j) {
      p0[j][i] = p0[p0[j][i - 1]][i - 1];
      p1[j][i] = p1[p1[j][i - 1]][i - 1];
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int tp, v, u;
    scanf("%d%d%d", &tp, &u, &v);
    if (tp == 1) {
      if (dep[v] <= dep[u]) {
        puts("NO");
        continue;
      }
      puts(goup(p0, v, dep[v] - dep[u]) == u ? "YES" : "NO");
    } else if (tp == 2) {
      puts(check(u, v) ? "YES" : "NO");
    } else
      assert(false);
  }
  return 0;
}
