#include <bits/stdc++.h>
const int logV = 17;
std::vector<std::vector<std::pair<int, int> > > adjList;
std::vector<int> tin, tout, depth, ccIdx, dist;
std::vector<std::vector<int> > up;
int timer = 0, n_cc = 0;
void travel(int vertex) {
  tin[vertex] = timer++;
  ccIdx[vertex] = n_cc;
  for (auto& v : adjList[vertex]) {
    depth[v.first] = depth[vertex] + 1;
    dist[v.first] = dist[vertex] + v.second;
    up[v.first][0] = vertex;
    for (int i = 1, up_v; i < logV; ++i) {
      up_v = up[v.first][i - 1];
      if (up_v != -1) up[v.first][i] = up[up_v][i - 1];
    }
    travel(v.first);
  }
  tout[vertex] = timer++;
}
int get_lca(int v1, int v2) {
  if (depth[v1] > depth[v2]) std::swap(v1, v2);
  for (int i = logV - 1; i >= 0; --i) {
    if (depth[v2] - depth[v1] >= (1 << i)) v2 = up[v2][i];
  }
  if (v1 == v2) return v1;
  for (int i = logV - 1; i >= 0; --i) {
    if (up[v1][i] != up[v2][i]) {
      v1 = up[v1][i], v2 = up[v2][i];
    }
  }
  return up[v1][0];
}
int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(0);
  int n_vertex;
  std::cin >> n_vertex;
  adjList.resize(n_vertex);
  for (int i = 0; i < n_vertex; ++i) {
    int parent, type;
    std::cin >> parent >> type;
    if (parent != -1) {
      adjList[--parent].emplace_back(i, type);
    }
  }
  tin.resize(n_vertex), tout.resize(n_vertex);
  depth.resize(n_vertex);
  up.resize(n_vertex, std::vector<int>(logV, -1));
  ccIdx.assign(n_vertex, -1);
  dist.resize(n_vertex);
  for (int i = 0; i < n_vertex; ++i) {
    if (ccIdx[i] == -1) travel(i), ++n_cc;
  }
  int n_query;
  std::cin >> n_query;
  while (n_query--) {
    int type, v1, v2;
    std::cin >> type >> v1 >> v2;
    --v1, --v2;
    if (type == 1) {
      std::cout << (ccIdx[v1] == ccIdx[v2] and tin[v1] < tin[v2] and
                            tout[v1] >= tout[v2] and dist[v1] == dist[v2]
                        ? "YES\n"
                        : "NO\n");
    } else {
      int lca = get_lca(v1, v2);
      std::cout << (ccIdx[v1] == ccIdx[v2] and lca != v2 and
                            dist[v1] == dist[lca] and
                            dist[v2] - dist[lca] == depth[v2] - depth[lca]
                        ? "YES\n"
                        : "NO\n");
    }
  }
  return 0;
}
