#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > graph[100000 + 5];
int in[100000 + 5], out[100000 + 5], up[100000 + 5][20], dis[3][100000 + 5],
    key[100000 + 5], cc, ticks;
void dfs(int root, int p) {
  up[root][0] = p;
  in[root] = ++ticks;
  key[root] = cc;
  for (int i = 1; i <= 18; ++i) up[root][i] = up[up[root][i - 1]][i - 1];
  for (auto z : graph[root]) {
    dis[0][z.first] = dis[0][root] + 1;
    dis[1][z.first] = dis[1][root] + (z.second == 0);
    dis[2][z.first] = dis[2][root] + (z.second == 1);
    dfs(z.first, root);
  }
  out[root] = ++ticks;
}
bool ok(int u, int v) { return in[u] <= in[v] and out[u] >= out[v]; }
int lca(int u, int v) {
  if (ok(u, v)) return u;
  if (ok(v, u)) return v;
  int z, i;
  for (i = 18; i >= 0; --i) {
    z = up[u][i];
    if (z and !ok(z, v)) u = z;
  }
  return up[u][0];
}
int main() {
  ios::sync_with_stdio(false);
  int n, u, v, q, w, type, i, d1, d2, d3, d4;
  cin >> n;
  for (i = 1; i <= n; ++i) {
    cin >> u >> type;
    if (u == -1) continue;
    graph[u].push_back({i, type});
  }
  for (i = 1; i <= n; ++i) {
    if (!key[i]) {
      ++cc;
      dfs(i, 0);
    }
  }
  cin >> q;
  while (q-- > 00) {
    cin >> type >> u >> v;
    if (u == v or key[u] != key[v])
      puts("NO");
    else if (type == 1) {
      d1 = dis[0][v] - dis[0][u];
      d2 = dis[1][v] - dis[1][u];
      puts(lca(u, v) == u and d1 == d2 ? "YES" : "NO");
    } else {
      w = lca(u, v);
      d1 = dis[0][u] - dis[0][w];
      d2 = dis[1][u] - dis[1][w];
      d3 = dis[0][v] - dis[0][w];
      d4 = dis[2][v] - dis[2][w];
      puts(w != v and d1 == d2 and d3 == d4 ? "YES" : "NO");
    }
  }
  return 0;
}
