#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5;
const long long MAXP = 20;
long long par[MAXP][MAXN];
long long depth[MAXN];
long long longestType[2][MAXN];
long long lca(long long u, long long v) {
  if (par[MAXP - 1][u] != par[MAXP - 1][v]) return -1;
  if (depth[u] < depth[v]) swap(u, v);
  long long d = depth[u] - depth[v];
  for (long long p(0); p < MAXP; ++p)
    if ((1 << p) & d) u = par[p][u];
  if (u == v) return u;
  for (long long p(MAXP - 1); p >= 0; --p)
    if (par[p][u] != par[p][v]) u = par[p][u], v = par[p][v];
  return par[0][u];
}
signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long nbSommets;
  cin >> nbSommets;
  for (long long iSommet = 0; iSommet < nbSommets; ++iSommet) {
    long long p, t;
    cin >> p >> t;
    if (p == -1) {
      par[0][iSommet] = iSommet;
      continue;
    }
    --p;
    par[0][iSommet] = p;
    depth[iSommet] = 1 + depth[p];
    if (t != -1) longestType[t][iSommet] = 1 + longestType[t][p];
  }
  for (long long p = 0; p < MAXP - 1; ++p) {
    for (long long i = 0; i < nbSommets; ++i) {
      par[p + 1][i] = par[p][par[p][i]];
    }
  }
  long long nbRequetes;
  cin >> nbRequetes;
  for (long long iRequete = 0; iRequete < nbRequetes; ++iRequete) {
    long long t, u, v;
    cin >> t >> u >> v;
    --u, --v;
    long long l = lca(u, v);
    if (t == 1) {
      if (u == v or l != u or longestType[0][v] < depth[v] - depth[u])
        cout << "NO";
      else
        cout << "YES";
    } else {
      if (l == -1 or l == v or longestType[1][v] < depth[v] - depth[l] or
          longestType[0][u] < depth[u] - depth[l])
        cout << "NO";
      else
        cout << "YES";
    }
    cout << '\n';
  }
}
