#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100500;
struct FenTree {
  ll a[N];
  FenTree() : a() {}
  void add(int v, ll x) {
    for (int i = v; i < N; i |= i + 1) a[i] += x;
  }
  ll get(int v) {
    ll s = 0;
    for (int i = v; i >= 0; i = (i & (i + 1)) - 1) s += a[i];
    return s;
  }
};
int n, q;
vector<int> pgo[N], sgo[N];
bool is_proot[N], is_sroot[N];
vector<pair<int, int>> query1[N], query2[N];
int psz[N], ppos[N], ppos_cnt;
bool in_stack[N];
FenTree fen;
bool res[N];
void dfs_prepare(int v) {
  ppos[v] = ppos_cnt++;
  psz[v] = 1;
  for (int to : pgo[v]) {
    dfs_prepare(to);
    psz[v] += psz[to];
  }
}
void dfs_work(int v) {
  int l = ppos[v];
  int r = l + psz[v];
  fen.add(l, +1);
  fen.add(r, -1);
  in_stack[v] = true;
  for (auto e : query1[v]) {
    int to = e.first;
    int id = e.second;
    res[id] = v != to && in_stack[to];
  }
  for (auto e : query2[v]) {
    int to = e.first;
    int id = e.second;
    res[id] = v != to && !in_stack[to] && fen.get(ppos[to]) > 0;
  }
  for (int to : sgo[v]) dfs_work(to);
  in_stack[v] = false;
  fen.add(l, -1);
  fen.add(r, +1);
}
void solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int p, t;
    scanf("%d%d", &p, &t);
    if (p == -1)
      is_proot[i] = is_sroot[i] = true;
    else {
      p--;
      if (t == 0) {
        sgo[p].push_back(i);
        is_proot[i] = true;
      } else {
        pgo[p].push_back(i);
        is_sroot[i] = true;
      }
    }
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int t, a, b;
    scanf("%d%d%d", &t, &a, &b);
    a--, b--;
    if (t == 1)
      query1[b].emplace_back(a, i);
    else
      query2[a].emplace_back(b, i);
  }
  for (int i = 0; i < n; i++)
    if (is_proot[i]) dfs_prepare(i);
  for (int i = 0; i < n; i++)
    if (is_sroot[i]) dfs_work(i);
  for (int i = 0; i < q; i++) puts(res[i] ? "YES" : "NO");
}
int main() {
  solve();
  (void)0;
}
