#include <bits/stdc++.h>
using namespace std;
template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}
vector<int> root(1e5 + 7, 0);
template <typename TP, const TP &(*F)(const TP &, const TP &)>
struct SegmentTree {
  int MAX;
  vector<TP> tree;
  SegmentTree(int n, TP zero) {
    MAX = 1 << (32 - __builtin_clz(n));
    tree.resize(2 * MAX + 7, zero);
  }
  SegmentTree(int n, vector<TP> &t) {
    MAX = 1 << (32 - __builtin_clz(n));
    tree.resize(2 * MAX + 7, {0, 0});
    for (int i = 0; i < (int)(t).size(); i++) tree[i + MAX] = t[i];
    for (int i = MAX - 1; i; i--) tree[i] = F(tree[2 * i], tree[2 * i + 1]);
  }
  void update(int id, TP val) {
    id += MAX, tree[id] = val;
    while (id > 1) {
      id >>= 1;
      tree[id] = F(tree[2 * id], tree[2 * id + 1]);
    }
  }
  TP query(int a, int b) {
    int va = a + MAX, vb = b + MAX;
    TP res = F(tree[va], tree[vb]);
    while (va / 2 != vb / 2) {
      if (va % 2 == 0) res = F(res, tree[va + 1]);
      if (vb % 2 == 1) res = F(res, tree[vb - 1]);
      va >>= 1, vb >>= 1;
    }
    return res;
  }
};
struct LCA {
  int n;
  vector<pair<int, int> > t;
  vector<int> g, d;
  vector<pair<int, int> > *G;
  SegmentTree<pair<int, int>, min> *tree;
  void dfs(int v, int f = 0) {
    g[v] = (int)(t).size();
    t.push_back({d[v], v});
    for (auto uu : G[v]) {
      int u = uu.first;
      if (u != f) {
        d[u] = d[v] + 1;
        dfs(u, v);
        t.push_back({d[v], v});
      }
    }
  }
  LCA(int N, vector<pair<int, int> > *V) : n(N), G(V) {
    g.resize(n + 1, 0);
    d.resize(n + 1, 0);
    for (int i = 1; i <= n; i++)
      if (root[i]) dfs(i);
    tree = new SegmentTree<pair<int, int>, min>((int)(t).size(), t);
  }
  pair<int, int> query(int a, int b) {
    if (g[a] > g[b]) swap(a, b);
    return tree->query(g[a], g[b]);
  }
  int dist(int a, int b) {
    if (g[a] > g[b]) swap(a, b);
    return d[a] + d[b] - 2 * tree->query(g[a], g[b]).first;
  }
};
const int N = 1e5 + 7;
int n, q, ile[N][2], sp[N];
vector<pair<int, int> > G[N];
int cnt;
void dfs(int v, int s, int ile0 = 0, int ile1 = 0) {
  cnt++;
  sp[v] = s;
  ile[v][0] = ile0, ile[v][1] = ile1;
  for (auto u : G[v]) {
    if (u.second == 0) {
      dfs(u.first, s, ile0 + 1, 0);
    } else {
      dfs(u.first, s, 0, ile1 + 1);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int p, t;
    cin >> p >> t;
    if (p != -1)
      G[p].push_back({i, t});
    else
      root[i] = true;
  }
  for (int i = 1; i <= n; i++) {
    if (!root[i]) continue;
    dfs(i, i);
  }
  LCA lca(n, G);
  assert(cnt == n);
  cin >> q;
  while (q--) {
    int t, a, b;
    cin >> t >> a >> b;
    if (sp[a] != sp[b] || a == b) {
      cout << "NO\n";
      continue;
    }
    if (t == 1) {
      pair<int, int> l = lca.query(a, b);
      if (l.second == a && ile[b][0] >= lca.dist(b, a))
        cout << "YES\n";
      else
        cout << "NO\n";
    } else {
      pair<int, int> l = lca.query(a, b);
      if (b != l.second && ile[a][0] >= lca.dist(a, l.second) &&
          ile[b][1] >= lca.dist(l.second, b))
        cout << "YES\n";
      else
        cout << "NO\n";
    }
  }
  return 0;
}
