#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
const long long inf = numeric_limits<long long>::max() / 2;
const long double eps = 1e-9;
const long double pi = acos(-1);
inline void solve(), read();
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  read();
  solve();
  return 0;
}
const long long LOG = 30;
struct edge {
  long long v, u, w;
};
struct graph {
  long long n;
  vector<vector<edge>> adj;
  graph() {}
  graph(long long n_) {
    n = n_;
    adj.resize(n);
  }
  void insert(long long v, long long u, long long w) {
    adj[v].push_back({v, u, w});
    adj[u].push_back({u, v, w});
  }
};
long long n, q;
graph g;
vector<long long> par, tin, tout, d;
long long timer = 0;
vector<vector<long long>> up, sum;
inline bool upper(long long a, long long b) {
  return tin[a] <= tin[b] && tout[a] >= tout[b];
}
long long lca(long long a, long long b) {
  if (up[a][LOG - 1] != up[b][LOG - 1]) {
    return -1;
  }
  if (upper(a, b)) {
    return a;
  }
  if (upper(b, a)) {
    return b;
  }
  for (long long i = LOG - 1; i >= 0; i--) {
    if (!upper(up[a][i], b)) {
      a = up[a][i];
    }
  }
  return up[a][0];
}
bool checkbit(long long n, long long p) { return n & (1ll << p); }
long long get_sum(long long v, long long u) {
  if (v == u) {
    return 0;
  }
  if (!upper(v, u)) {
    swap(v, u);
  }
  long long dist = d[u] - d[v];
  long long ans = 0;
  for (long long i = LOG - 1; i >= 0; i--) {
    if (checkbit(dist, i)) {
      ans += sum[u][i];
      u = up[u][i];
    }
  }
  return ans;
}
void dfs(long long v, long long p, long long w, long long dep) {
  d[v] = dep;
  tin[v] = timer++;
  up[v][0] = p;
  sum[v][0] = w;
  for (long long i = 1; i < LOG; i++) {
    up[v][i] = up[up[v][i - 1]][i - 1];
    sum[v][i] = sum[up[v][i - 1]][i - 1] + sum[v][i - 1];
  }
  for (edge e : g.adj[v]) {
    long long u = (e.v == v) ? e.u : e.v;
    if (u == p) {
      continue;
    }
    dfs(u, v, e.w, dep + 1);
  }
  tout[v] = timer++;
}
long long query1(long long v, long long u) {
  long long c = lca(v, u);
  if (c == -1) {
    return 0;
  }
  if (c != v) {
    return 0;
  }
  long long a1 = get_sum(c, v) == 0;
  long long a2 = get_sum(c, u) == 0;
  return a1 && a2;
}
long long query2(long long v, long long u) {
  long long c = lca(v, u);
  if (c == -1) {
    return 0;
  }
  if (c == u) {
    return 0;
  }
  long long a1 = get_sum(c, v) == 0;
  long long a2 = get_sum(c, u) == d[u] - d[c];
  return a1 && a2;
}
inline void solve() {
  tin.resize(n), tout.resize(n), d.resize(n, 0);
  up.resize(n, vector<long long>(LOG, -1)),
      sum.resize(n, vector<long long>(LOG, 0));
  for (long long i = 0; i < n; i++) {
    if (par[i] == -1) {
      dfs(i, i, 0, 0);
    }
  }
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long t, v, u;
    cin >> t >> v >> u;
    --v, --u;
    long long ans = 0;
    if (v == u) {
      ans = 0;
    } else if (t == 1) {
      ans = query1(v, u);
    } else if (t == 2) {
      ans = query2(v, u);
    }
    cout << (ans ? "YES" : "NO") << "\n";
  }
}
inline void read() {
  cin >> n;
  g = graph(n);
  par.resize(n, -1);
  for (long long i = 0; i < n; i++) {
    long long p, t;
    cin >> p >> t;
    --p;
    if (p != -2) {
      par[i] = p;
      g.insert(p, i, t);
    }
  }
}
