#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5 + 5;
const int MaxLogN = 20;
pair<int, int> sum[MaxN];
int p[MaxN], lc[MaxN][MaxLogN];
int depth[MaxN], type[MaxN];
int lca(int u, int v) {
  int dif = depth[u] - depth[v];
  if (dif < 0) {
    swap(u, v);
    dif *= -1;
  }
  for (int i = MaxLogN - 1; i >= 0; i--)
    if ((dif >> i) & 1) u = lc[u][i];
  if (u == v) return u;
  for (int i = MaxLogN - 1; i >= 0; i--) {
    if (lc[u][i] != lc[v][i]) {
      u = lc[u][i];
      v = lc[v][i];
    }
  }
  return lc[u][0];
}
int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i] >> type[i];
    if (p[i] != -1) {
      depth[i] = depth[p[i]] + 1;
      sum[i].first = sum[p[i]].first + (type[i] == 0);
      sum[i].second = sum[p[i]].second + (type[i] == 1);
      lc[i][0] = p[i];
    }
  }
  for (int j = 1; j < MaxLogN; j++)
    for (int i = 1; i <= n; i++) lc[i][j] = lc[lc[i][j - 1]][j - 1];
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int t, u, v;
    cin >> t >> u >> v;
    int lc_n = lca(u, v);
    if (lc_n == 0) {
      cout << "NO" << endl;
      continue;
    }
    if (lc_n == v) {
      cout << "NO" << endl;
      continue;
    }
    if (t == 1) {
      if (lc_n == u && sum[v].second - sum[u].second == 0)
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    } else {
      if (sum[v].first - sum[lc_n].first == 0 &&
          sum[u].second - sum[lc_n].second == 0)
        cout << "YES" << endl;
      else
        cout << "NO" << endl;
    }
  }
  return 0;
}
