#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000007;
const long long linf = 1ll * inf * inf;
const int N = 100000 + 7;
const int multipleTest = 0;
vector<pair<int, int> > adj[N];
int pa[N][20];
int depth[N];
int g[N];
int root[N];
int k = 0;
int n;
int low[N];
int high[N];
int rr = 0;
int curRoot;
void dfs(int u, int r) {
  pa[u][0] = r;
  low[u] = ++rr;
  for (int j = 1; j < 20; ++j) {
    if (pa[u][j - 1] == -1)
      pa[u][j] = -1;
    else
      pa[u][j] = pa[pa[u][j - 1]][j - 1];
  }
  root[u] = curRoot;
  for (pair<int, int> x : adj[u]) {
    int v = x.first;
    int c = x.second;
    if (v != r) {
      depth[v] = depth[u] + 1;
      g[v] = g[u] + c;
      dfs(v, u);
    }
  }
  high[u] = rr;
}
bool isPa(int r, int u) { return low[r] <= low[u] && high[r] >= high[u]; }
int LCA(int u, int v) {
  if (depth[u] < depth[v]) swap(u, v);
  while (depth[u] > depth[v]) {
    int k = log2(depth[u] - depth[v]);
    u = pa[u][k];
  }
  if (u == v) return u;
  for (int j = 19; j >= 0; --j) {
    if (pa[u][j] != -1 && pa[v][j] != pa[u][j]) {
      u = pa[u][j];
      v = pa[v][j];
    }
  }
  return pa[u][0];
}
void solve() {
  cin >> n;
  for (int i = (1), _b = (n + 1); i < _b; ++i) {
    int u, c;
    scanf("%d%d", &u, &c);
    if (u != -1)
      adj[u].push_back(make_pair(i, c));
    else
      pa[i][0] = -1;
  }
  for (int i = (1), _b = (n + 1); i < _b; ++i)
    if (pa[i][0] == -1) {
      curRoot = i;
      dfs(i, -1);
    }
  int q;
  cin >> q;
  while (q-- > 0) {
    int op, u, v;
    scanf("%d%d%d", &op, &u, &v);
    if (root[u] != root[v] || u == v) {
      puts("NO");
      continue;
    }
    if (op == 1) {
      if (isPa(u, v) && g[v] - g[u] == 0)
        puts("YES");
      else
        puts("NO");
    } else {
      int r = LCA(u, v);
      if (r == u) {
        if (g[v] - g[u] == depth[v] - depth[u])
          puts("YES");
        else
          puts("NO");
      } else if (r == v) {
        puts("NO");
      } else {
        if (g[u] - g[r] == 0 && g[v] - g[r] == depth[v] - depth[r])
          puts("YES");
        else
          puts("NO");
      }
    }
  }
}
int main() {
  int Test = 1;
  if (multipleTest) {
    cin >> Test;
  }
  for (int i = 0; i < Test; ++i) {
    solve();
  }
}
