#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 101000 + 10;
vector<int> graph[nax], h(nax);
int par[nax][32];
const int MAXLOG = 20;
vector<int> roots;
int part[nax], special[nax], type[nax], n, q;
void dfs(int v, int p = -1) {
  if (p != -1) h[v] = 1 + h[p];
  par[v][0] = p;
  for (int i = 1; i < MAXLOG; i++) {
    if (par[v][i - 1] != -1) par[v][i] = par[par[v][i - 1]][i - 1];
  }
  for (auto x : graph[v]) {
    if (x != p) dfs(x, v);
  }
}
int query(int u, int v) {
  if (h[v] < h[u]) swap(v, u);
  for (int i = MAXLOG - 1; i >= 0; i--) {
    if (h[par[v][i]] >= h[u] && par[v][i] != -1) v = par[v][i];
  }
  if (u == v) return v;
  for (int i = MAXLOG - 1; i >= 0; i--) {
    if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];
  }
  return par[v][0];
}
void naklidfs(int v, int parti, int speciali, int par) {
  part[v] = parti;
  special[v] = speciali;
  for (auto x : graph[v]) {
    if (x == par) continue;
    if (type[x] == 0)
      naklidfs(x, parti, speciali + 1, v);
    else
      naklidfs(x, parti + 1, speciali, v);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int pare, types;
    cin >> pare >> types;
    if (pare == -1 && types == -1) {
      roots.push_back(i);
      continue;
    }
    type[i] = types;
    graph[pare].push_back(i);
  }
  cin >> q;
  memset(par, -1, sizeof(par));
  for (auto x : roots) {
    dfs(x);
    naklidfs(x, 0, 0, -1);
  }
  while (q--) {
    int types, u, v;
    cin >> types;
    if (types == 1) {
      cin >> u >> v;
      int lca = query(u, v);
      if (lca == -1) {
        cout << "NO" << endl;
        continue;
      }
      if (lca != u || u == v) {
        cout << "NO" << endl;
        continue;
      }
      int heights = h[v] - h[u];
      int specials = special[v] - special[u];
      if (heights != specials)
        cout << "NO" << endl;
      else
        cout << "YES" << endl;
    } else {
      cin >> u >> v;
      int lca = query(u, v);
      if (lca == v || lca == -1) {
        cout << "NO" << endl;
        continue;
      }
      int heights1 = h[u] - h[lca];
      int specials = special[u] - special[lca];
      int heights2 = h[v] - h[lca];
      int parts = part[v] - part[lca];
      if (heights1 != specials || heights2 != parts)
        cout << "NO" << endl;
      else
        cout << "YES" << endl;
    }
  }
  return 0;
}
