#include <bits/stdc++.h>
using namespace std;
long long int n, dis[100005], timer, l = 19, tin[100005], tout[100005],
                                     up[100005][20];
long long int par[100005], ty[100005], spl[100005], root[100005];
vector<pair<long long int, long long int> > g[100005];
void dfs(long long int st, long long int pr, long long int isSpl,
         long long int rt) {
  tin[st] = ++timer;
  up[st][0] = pr;
  dis[st] = 1 + dis[pr];
  spl[st] = isSpl + spl[pr];
  root[st] = rt;
  for (long long int i = 1; i <= l; ++i) up[st][i] = up[up[st][i - 1]][i - 1];
  for (auto xp : g[st]) {
    dfs(xp.first, st, xp.second, rt);
  }
  tout[st] = ++timer;
}
bool upper(long long int a, long long int b) {
  return tin[a] <= tin[b] && tout[a] >= tout[b];
}
long long int lca(long long int a, long long int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (long long int i = l; i >= 0; --i)
    if (!upper(up[a][i], b)) a = up[a][i];
  return up[a][0];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (long long int i = 1; i <= n; ++i) {
    cin >> par[i] >> ty[i];
    if (par[i] == -1)
      ty[i] = 0;
    else {
      ty[i] = !ty[i];
      g[par[i]].push_back(make_pair(i, ty[i]));
    }
  }
  for (long long int i = 1; i <= n; ++i)
    if (par[i] == -1) dfs(i, i, ty[i], i);
  long long int q;
  cin >> q;
  while (q--) {
    long long int t, u, v;
    cin >> t >> u >> v;
    if (root[u] != root[v] || u == v) {
      cout << "NO\n";
      continue;
    }
    long long int lc = lca(u, v);
    if (t == 1) {
      if (lc == u && dis[v] - dis[u] == spl[v] - spl[u]) {
        cout << "YES\n";
      } else
        cout << "NO\n";
    } else {
      if (dis[u] - dis[lc] == spl[u] - spl[lc] && v != lc &&
          spl[v] == spl[lc]) {
        cout << "YES\n";
      } else
        cout << "NO\n";
    }
  }
}
