#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 3;
int n, q, p, ttype, height[maxn], first[maxn], t[8 * maxn], u, v;
vector<int> euler, roots;
vector<int> adjs[maxn], sc_adjs[maxn], pa_adjs[maxn];
bool vis[maxn], compovis[maxn];
int cnt, compo_id[maxn], sc_compoid[maxn], pa_compoid[maxn];
void build(int v, int tl, int tr) {
  if (tl == tr)
    t[v] = euler[tl];
  else {
    int tm = (tl + tr) / 2;
    build(2 * v, tl, tm);
    build(2 * v + 1, tm + 1, tr);
    int l = t[2 * v], r = t[2 * v + 1];
    t[v] = (height[l] <= height[r]) ? l : r;
  }
}
void dfs(int u, int h) {
  vis[u] = 1;
  first[u] = euler.size();
  height[u] = h;
  compo_id[u] = cnt;
  euler.push_back(u);
  for (int v : adjs[u])
    if (!vis[v]) {
      dfs(v, h + 1);
      euler.push_back(u);
    }
}
void sc_component(int u) {
  compovis[u] = 1;
  sc_compoid[u] = cnt;
  for (int v : sc_adjs[u])
    if (!compovis[v]) sc_component(v);
}
void pa_component(int u) {
  compovis[u] = 1;
  pa_compoid[u] = cnt;
  for (int v : pa_adjs[u])
    if (!compovis[v]) pa_component(v);
}
int query(int v, int tl, int tr, int l, int r) {
  if (l > r) return -1;
  if (tl == l && tr == r) return t[v];
  int tm = (tl + tr) / 2;
  int p1 = query(2 * v, tl, tm, l, min(tm, r));
  int p2 = query(2 * v + 1, tm + 1, tr, max(tm + 1, l), r);
  if (p1 == -1) return p2;
  if (p2 == -1) return p1;
  return (height[p1] <= height[p2]) ? p1 : p2;
}
int lca(int u, int v) {
  if (first[u] > first[v]) swap(u, v);
  return query(1, 0, euler.size() - 1, first[u], first[v]);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d %d", &p, &ttype);
    if (p == -1 && ttype == -1)
      roots.push_back(i);
    else {
      p--;
      adjs[p].push_back(i);
      if (ttype == 0)
        sc_adjs[p].push_back(i);
      else if (ttype == 1)
        pa_adjs[p].push_back(i);
    }
  }
  for (int root : roots) cnt++, dfs(root, 0);
  build(1, 0, euler.size() - 1);
  cnt = 0;
  for (int i = 0; i < n; i++)
    if (!compovis[i]) cnt++, sc_component(i);
  cnt = 0;
  fill_n(compovis, n, 0);
  for (int i = 0; i < n; i++)
    if (!compovis[i]) cnt++, pa_component(i);
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d %d", &ttype, &u, &v);
    u--, v--;
    if (u == v) {
      cout << "NO" << endl;
      continue;
    }
    int p = lca(u, v);
    if (ttype == 1) {
      if (p == u && sc_compoid[u] == sc_compoid[v]) {
        cout << "YES" << endl;
        continue;
      }
    } else {
      if (p != v && sc_compoid[p] == sc_compoid[u] &&
          pa_compoid[p] == pa_compoid[v]) {
        cout << "YES" << endl;
        continue;
      }
    }
    cout << "NO" << endl;
  }
}
