#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
vector<int> adj[2][100009];
int n;
int in, head[100009 + 100009];
int p[2][100009], rep[2][100009], b[2][100009], e[2][100009];
int top;
void dfs(int t, int u, int id) {
  rep[t][u] = id;
  b[t][u] = top++;
  int sz = adj[t][u].size();
  for (int(i) = (0); (i) < (sz); ++(i)) {
    int v = adj[t][u][i];
    dfs(t, v, id);
  }
  e[t][u] = top;
}
void build(int t, int u, int id) {
  top = 0;
  dfs(t, u, id);
  head[id] = u;
}
bool desc(int t, int u, int v) {
  if (rep[t][u] != rep[t][v]) return 0;
  int lo = b[t][u], hi = e[t][u], ps = b[t][v];
  return (ps >= lo && ps < hi);
}
int main() {
  while (scanf("%d", &n) == 1) {
    memset((p[0]), (-1), sizeof(p[0]));
    memset((p[1]), (-1), sizeof(p[1]));
    for (int(j) = (0); (j) < (2); ++(j))
      for (int(i) = (0); (i) < (n); ++(i)) {
        adj[j][i].clear();
      }
    for (int(i) = (0); (i) < (n); ++(i)) {
      int pp, tp;
      scanf("%d%d", &pp, &tp);
      pp--;
      if (tp == -1) continue;
      p[tp][i] = pp;
      adj[tp][pp].push_back(i);
    }
    in = 0;
    for (int(i) = (0); (i) < (n); ++(i)) {
      if (p[0][i] == -1) build(0, i, in++);
      if (p[1][i] == -1) build(1, i, in++);
    }
    int q;
    scanf("%d", &q);
    while (q--) {
      int t, u, v;
      scanf("%d%d%d", &t, &u, &v);
      u--;
      v--;
      if (t == 1) {
        if (u == v)
          puts("NO");
        else
          puts(desc(0, u, v) ? "YES" : "NO");
      } else {
        if (p[1][v] == -1)
          puts("NO");
        else {
          int idu = rep[0][u];
          int hu = head[idu];
          int idv = rep[1][v];
          int hv = head[idv];
          if (v != hu && desc(1, hu, v))
            puts("YES");
          else if (hv != v && desc(0, hv, u))
            puts("YES");
          else
            puts("NO");
        }
      }
    }
  }
  return 0;
}
