#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
using ll = long long;
using ld = long double;
constexpr int nax = 1000 * 1000 + 105;
constexpr int infty = 1000 * 1000 * 1000 + 5;
constexpr int mod = 1000 * 1000 * 1000 + 7;
constexpr int Log = 20;
int n;
int part[Log][nax];
vector<int> graf[2][nax];
int pre_it[2];
int pre[2][nax], pos[2][nax];
void dfs(int id, int w) {
  pre[id][w] = ++pre_it[id];
  for (int a : graf[id][w]) {
    dfs(id, a);
  }
  pos[id][w] = pre_it[id];
}
bool Special(int id, int a, int b) {
  return pre[id][b] <= pre[id][a] and pos[id][a] <= pos[id][b];
}
bool Query(int t, int u, int v) {
  debug() << "Query("
             " ["
          << "t"
             ": "
          << (t)
          << "] "
             " ["
          << "u"
             ": "
          << (u)
          << "] "
             " ["
          << "v"
             ": "
          << (v)
          << "] "
             ")";
  if (u == v) return false;
  if (t == 1) {
    return Special(0, v, u);
  }
  assert(t == 2);
  debug() << " ["
          << "t == 2"
             ": "
          << (t == 2) << "] ";
  debug() << " ["
          << "part[0][v]"
             ": "
          << (part[0][v]) << "] ";
  debug() << " ["
          << "Special(1, u, v)"
             ": "
          << (Special(1, u, v)) << "] ";
  if (Special(1, u, v)) return false;
  if (v == part[0][v]) return false;
  v = part[0][v];
  debug() << " ["
          << "v"
             ": "
          << (v) << "] ";
  if (!Special(1, u, v)) {
    for (int l = Log - 1; l >= 0; l--) {
      if (!Special(1, u, part[l][v])) {
        v = part[l][v];
      }
    }
    assert(!Special(1, u, v));
    v = part[0][v];
  }
  debug() << " ["
          << "u"
             ": "
          << (u)
          << "] "
             " ["
          << "v"
             ": "
          << (v) << "] ";
  return Special(0, u, v);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    part[0][i] = i;
    int a, type;
    scanf("%d%d", &a, &type);
    if (type == 0) {
      graf[0][a].push_back(i);
      graf[1][a].push_back(i);
    } else if (type == 1) {
      graf[0][0].push_back(i);
      graf[1][a].push_back(i);
      part[0][i] = a;
    } else {
      assert(type == -1);
      assert(a == -1);
      graf[0][0].push_back(i);
      graf[1][0].push_back(i);
    }
  }
  for (int l = 1; l < Log; l++) {
    for (int i = 1; i <= n; i++) {
      part[l][i] = part[l - 1][part[l - 1][i]];
    }
  }
  dfs(0, 0);
  dfs(1, 0);
  int q;
  scanf("%d", &q);
  while (q--) {
    int t, u, v;
    scanf("%d%d%d", &t, &u, &v);
    printf("%s\n", Query(t, u, v) ? "YES" : "NO");
  }
  return 0;
}
