#include <bits/stdc++.h>
using namespace std;
static const int maxn = 1e5 + 5;
static const int logn = 19;
struct Node {
  int v, w;
  Node(int v = 0, int w = 0) : v(v), w(w) {}
};
vector<vector<Node> > graph;
int depth[maxn];
int father[maxn][logn];
int cost[maxn][2];
int compo[maxn];
void dfs(int u, int c) {
  compo[u] = c;
  for (int i = 1; i < logn; i++) father[u][i] = father[father[u][i - 1]][i - 1];
  for (Node it : graph[u]) {
    int v = it.v;
    int w = it.w;
    depth[v] = depth[u] + 1;
    father[v][0] = u;
    for (int i = 0; i < 2; i++) cost[v][i] = cost[u][i];
    cost[v][w]++;
    dfs(v, c);
  }
}
int find_lca(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  for (int i = logn - 1; i >= 0; i--) {
    if (depth[father[u][i]] >= depth[v]) u = father[u][i];
  }
  if (u == v) return u;
  for (int i = logn - 1; i >= 0; i--) {
    if (father[u][i] != father[v][i]) {
      u = father[u][i];
      v = father[v][i];
    }
  }
  return father[u][0];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector<int> par;
  graph.resize(n + 1);
  for (int v = 1; v <= n; v++) {
    int u, w;
    cin >> u >> w;
    if (u == -1) {
      par.push_back(v);
      continue;
    }
    graph[u].emplace_back(v, w);
  }
  int c = 0;
  for (int p : par) {
    depth[p] = 1;
    ++c;
    dfs(p, c);
  }
  int q;
  cin >> q;
  while (q--) {
    int type, u, v;
    cin >> type >> u >> v;
    if (compo[u] != compo[v] or u == v) {
      cout << "NO" << '\n';
      continue;
    }
    if (type == 1) {
      int lca = find_lca(u, v);
      if (lca != u) {
        cout << "NO" << '\n';
        continue;
      }
      int d = depth[v] - depth[lca];
      int c = cost[v][0] - cost[lca][0];
      if (c != d)
        cout << "NO" << '\n';
      else
        cout << "YES" << '\n';
    } else {
      int lca = find_lca(u, v);
      int d_u = depth[u] - depth[lca];
      int d_v = depth[v] - depth[lca];
      if (lca == u and cost[v][1] - cost[lca][1] == d_v) {
        cout << "YES" << '\n';
        continue;
      }
      if (lca == v) {
        cout << "NO" << '\n';
        continue;
      }
      if (cost[u][0] - cost[lca][0] == d_u and
          cost[v][1] - cost[lca][1] == d_v) {
        cout << "YES" << '\n';
      } else {
        cout << "NO" << '\n';
      }
    }
  }
}
