#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const long long linf = (long long)1e18;
const int mod = (int)1e9 + 7;
const long double eps = (long double)1e-8;
const int maxn = (int)1e5 + 5;
const long double pi = acos(-1);
const int MX = 20;
int n, tim;
int tin[maxn], tout[maxn], p[maxn][MX + 2], len[maxn], h[maxn];
vector<pair<int, int> > a[maxn];
void dfs(int v, int pr = 0, int l = 0) {
  p[v][0] = pr;
  for (auto i = 1; i != MX; ++i) p[v][i] = p[p[v][i - 1]][i - 1];
  h[v] = h[pr] + 1;
  tin[v] = ++tim;
  len[v] = l;
  for (auto i = 0; i != (int)a[v].size(); ++i) {
    int to = a[v][i].first;
    int tol = l;
    if (a[v][i].second == 0)
      tol = min(-1, l - 1);
    else
      tol = max(1, l + 1);
    dfs(to, v, tol);
  }
  tout[v] = tim;
}
int is_par(int x, int y) { return (tin[x] <= tin[y] && tout[x] >= tout[y]); }
int lca(int x, int y) {
  if (is_par(x, y)) return x;
  if (is_par(y, x)) return y;
  for (int i = MX - 1; i >= 0; --i) {
    int tox = p[x][i];
    if (!is_par(tox, y)) x = tox;
  }
  return p[x][0];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (auto i = 1; i != n + 1; ++i) {
    int p, typ;
    cin >> p >> typ;
    if (p == -1) continue;
    a[p].push_back(make_pair(i, typ));
  }
  memset((tin), 0, sizeof(tin));
  memset((p), 0, sizeof(p));
  tim = 0;
  h[0] = 0;
  tin[0] = -1;
  for (auto i = 1; i != n + 1; ++i) {
    if (tin[i] > 0) continue;
    dfs(i);
  }
  tout[0] = tim + 1;
  int T;
  cin >> T;
  for (auto numt = 0; numt != T; ++numt) {
    int typ, u, v;
    cin >> typ >> u >> v;
    if (u == v) {
      cout << "NO" << endl;
      continue;
    }
    if (typ == 1) {
      if (is_par(u, v) && (-len[v]) >= h[v] - h[u])
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    } else {
      if (is_par(u, v)) {
        if (len[v] >= h[v] - h[u])
          cout << "YES" << endl;
        else
          cout << "NO" << endl;
        continue;
      }
      if (is_par(v, u)) {
        cout << "NO" << endl;
        continue;
      }
      int z = lca(u, v);
      if ((-len[u]) >= h[u] - h[z] && len[v] >= h[v] - h[z])
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  }
  return 0;
}
