#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const int MAXN = 100500;
const int LOG = 19;
int jump_to[LOG][MAXN];
int cnt_edges[2][LOG][MAXN];
int depth[MAXN];
int root[MAXN];
int get_edges(int v, int type, int k) {
  int answer = 0;
  for (int i = LOG - 1; i >= 0; i--) {
    if (k < (1 << i)) continue;
    answer += cnt_edges[type][i][v];
    v = jump_to[i][v];
    k -= 1 << i;
  }
  return answer;
}
int get_jump(int v, int k) {
  for (int i = LOG - 1; i >= 0; i--) {
    if (k < (1 << i)) continue;
    v = jump_to[i][v];
    k -= 1 << i;
  }
  return v;
}
int get_lca(int v, int u) {
  if (depth[v] > depth[u])
    v = get_jump(v, depth[v] - depth[u]);
  else
    u = get_jump(u, depth[u] - depth[v]);
  if (u == v) return v;
  for (int i = LOG - 1; i >= 0; i--) {
    int v1 = jump_to[i][v];
    int u1 = jump_to[i][u];
    if (v1 != u1) {
      v = v1;
      u = u1;
    }
  }
  return get_jump(v, 1);
}
void append(int v, int par, int tp) {
  depth[v] = depth[par] + 1;
  jump_to[0][v] = par;
  cnt_edges[tp][0][v] = 1;
  for (int i = 1; i < LOG; i++) {
    jump_to[i][v] = jump_to[i - 1][jump_to[i - 1][v]];
    for (int j = 0; j < 2; j++) {
      cnt_edges[j][i][v] =
          cnt_edges[j][i - 1][v] + cnt_edges[j][i - 1][jump_to[i - 1][v]];
    }
  }
}
const string yes = "YES";
const string no = "NO";
string is_instance(int obj, int cls) {
  if (obj == cls) return no;
  if (root[obj] != root[cls]) return no;
  if (get_lca(obj, cls) != cls) return no;
  int len = depth[obj] - depth[cls];
  return get_edges(obj, 0, len) == len ? yes : no;
}
string is_part(int obj, int whole) {
  if (obj == whole) return no;
  if (root[obj] != root[whole]) return no;
  int lca = get_lca(obj, whole);
  if (lca != whole and is_instance(whole, lca) == no) return no;
  if (lca == obj) return no;
  int len = depth[obj] - depth[lca];
  return get_edges(obj, 1, len) == len ? yes : no;
}
void init_root(int v) {
  root[v] = v;
  depth[v] = 0;
  for (int i = 0; i < LOG; i++) {
    jump_to[i][v] = v;
    cnt_edges[0][i][v] = cnt_edges[1][i][v] = 0;
  }
}
int main() {
  cin.sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int parent, type;
    cin >> parent >> type;
    if (parent == -1) {
      init_root(i);
    } else {
      append(i, parent, type);
      root[i] = get_jump(i, MAXN);
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int type;
    int u, v;
    cin >> type >> u >> v;
    if (type == 1)
      cout << is_instance(v, u) << "\n";
    else
      cout << is_part(v, u) << "\n";
  }
  return 0;
}
