#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
vector<int> g[maxn], f[maxn];
vector<int> A1[maxn], id1[maxn];
vector<int> A2[maxn], id2[maxn];
int ans[maxn];
int v[maxn];
int tims = 0;
vector<int> tmp;
void dfs1(int x, int tim) {
  for (int i = 0; i < g[x].size(); i++) {
    dfs1(g[x][i], ++tims);
  }
  int sz = tmp.size();
  for (int i = 0; i < f[x].size(); i++) {
    dfs1(f[x][i], tim);
    while (tmp.size() > sz) v[tmp.back()] = 0, tmp.pop_back();
  }
  for (int i = 0; i < A1[x].size(); i++) {
    if (v[A1[x][i]] > tim)
      ans[id1[x][i]] = 1;
    else
      ans[id1[x][i]] = 0;
  }
  v[x] = tim;
  tmp.push_back(x);
}
void dfs2(int x, set<int> &S, vector<int> &SS) {
  S.insert(x), SS.push_back(x);
  for (int i = 0; i < g[x].size(); i++) {
    set<int> s;
    vector<int> ss;
    dfs2(g[x][i], s, ss);
  }
  for (int i = 0; i < f[x].size(); i++) {
    dfs2(f[x][i], S, SS);
  }
  S.erase(x), SS.pop_back();
  for (int i = 0; i < A2[x].size(); i++) {
    if (S.count(A2[x][i]))
      ans[id2[x][i]] = 1;
    else
      ans[id2[x][i]] = 0;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int fa, p;
    scanf("%d%d", &fa, &p);
    if (fa < 0) fa = 0;
    if (p == 0)
      f[fa].push_back(i);
    else
      g[fa].push_back(i);
  }
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int op, u, v;
    scanf("%d%d%d", &op, &u, &v);
    if (op == 1)
      A2[v].push_back(u), id2[v].push_back(i);
    else
      A1[u].push_back(v), id1[u].push_back(i);
  }
  for (int i = 0; i < g[0].size(); i++) {
    dfs1(g[0][i], 0);
    for (int i = 0; i < tmp.size(); i++) v[tmp[i]] = 0;
    tmp.clear();
  }
  for (int i = 0; i < g[0].size(); i++) {
    set<int> s;
    vector<int> ss;
    dfs2(g[0][i], s, ss);
  }
  for (int i = 0; i < q; i++) {
    ans[i] ? puts("YES") : puts("NO");
  }
}
