#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > g[100010];
int nxt[100010][20], status[100010][20], n, root[100010], dep[100010];
bool vis[100010];
void dfs(int u, int d, int rt) {
  vis[u] = true;
  root[u] = rt;
  dep[u] = d;
  for (pair<int, int>& e : g[u]) {
    nxt[e.first][0] = u;
    status[e.first][0] = e.second;
    dfs(e.first, d + 1, rt);
  }
}
void init() {
  memset(nxt, -1, sizeof nxt);
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs(i, 1, i);
  for (int k = 1; k < 20; k++) {
    for (int i = 1; i <= n; i++) {
      if (nxt[i][k - 1] != -1) {
        status[i][k] = status[i][k - 1] | status[nxt[i][k - 1]][k - 1];
        nxt[i][k] = nxt[nxt[i][k - 1]][k - 1];
      }
    }
  }
}
pair<int, int> find_lca(int u, int v) {
  if (root[u] != root[v] || u == v) return pair<int, int>(-1, -1);
  int path_status = 0;
  if (dep[u] > dep[v]) swap(u, v);
  for (int k = 19; k >= 0; k--)
    if (nxt[v][k] != -1 && dep[u] <= dep[nxt[v][k]]) {
      path_status |= status[v][k];
      v = nxt[v][k];
    }
  if (u == v) return pair<int, int>(v, path_status);
  for (int k = 19; k >= 0; k--) {
    if (nxt[v][k] != nxt[u][k]) {
      path_status |= status[v][k] | status[u][k];
      v = nxt[v][k];
      u = nxt[u][k];
    }
  }
  path_status |= status[v][0] | status[u][0];
  v = nxt[v][0];
  u = nxt[u][0];
  return pair<int, int>(v, path_status);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int q, par, tp, o, u, v;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> par >> tp;
    if (tp != -1) g[par].push_back(pair<int, int>(i, tp + 1));
  }
  init();
  cin >> q;
  while (q--) {
    cin >> o >> u >> v;
    pair<int, int> lca = find_lca(u, v);
    if (o == 1) {
      if (lca.first != u || lca.second != 1)
        cout << "NO\n";
      else
        cout << "YES\n";
    } else {
      if (lca.first == u && lca.second == 2)
        cout << "YES\n";
      else {
        if (lca.first == -1)
          cout << "NO\n";
        else {
          pair<int, int> lca2 = find_lca(lca.first, v),
                         lca3 = find_lca(lca.first, u);
          if (lca2.second == 2 && lca3.second == 1)
            cout << "YES\n";
          else
            cout << "NO\n";
        }
      }
    }
  }
  return 0;
}
