#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 9;
int n, dist[MAX], color[MAX], colorsCnt;
int in[MAX], out[MAX], dfsCnt;
int depth[MAX], spt[MAX][20], lg2[MAX];
vector<pair<int, int> > adj[MAX];
void Dfs(int node) {
  in[node] = ++dfsCnt;
  color[node] = colorsCnt;
  for (const pair<int, int>& p : adj[node]) {
    int child = p.first;
    depth[child] = depth[node] + 1;
    dist[child] = dist[node] + p.second;
    spt[child][0] = node;
    for (int j = 1; (1 << j) <= n; ++j) {
      spt[child][j] = spt[spt[child][j - 1]][j - 1];
    }
    Dfs(child);
  }
  out[node] = dfsCnt;
}
int GetLca(int x, int y) {
  if (depth[x] > depth[y]) {
    swap(x, y);
  }
  for (int k = lg2[n]; k >= 0; --k) {
    if (depth[y] - (1 << k) >= depth[x]) {
      y = spt[y][k];
    }
  }
  if (x == y) {
    return x;
  }
  for (int k = lg2[n]; k >= 0; --k) {
    if (spt[x][k] != spt[y][k]) {
      x = spt[x][k];
      y = spt[y][k];
    }
  }
  return spt[x][0];
}
bool IsAncestor(int x, int y) { return in[x] < in[y] && out[x] >= out[y]; }
bool IsSpecialCase(int x, int y) { return (dist[x] - dist[y] == 0); }
bool IsPart(int x, int y) { return (dist[x] - dist[y] == depth[x] - depth[y]); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    lg2[i] = lg2[i >> 1] + 1;
  }
  for (int i = 1; i <= n; ++i) {
    int parent, type;
    cin >> parent >> type;
    if (parent != -1) {
      adj[parent].push_back({i, type});
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (!color[i]) {
      ++colorsCnt;
      Dfs(i);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int op, u, v;
    cin >> op >> u >> v;
    if (op == 1) {
      if (color[u] == color[v] && IsAncestor(u, v) && IsSpecialCase(v, u)) {
        cout << "YES\n";
      } else {
        cout << "NO\n";
      }
    } else {
      int lca = GetLca(u, v);
      if (color[u] == color[v] && lca != v && IsSpecialCase(u, lca) &&
          IsPart(v, lca)) {
        cout << "YES\n";
      } else {
        cout << "NO\n";
      }
    }
  }
  return 0;
}
