#include <bits/stdc++.h>
using namespace std;
double PI = 3.1415926535897932384626;
const long long LG = 31;
long long n, q;
long long tim = 0;
long long parent[LG][100005];
long long mx[LG][100005];
long long tin[100005], tout[100005], level[100005];
vector<pair<long long, long long> > g[100005];
void dfs(long long k, long long par, long long lvl) {
  tin[k] = ++tim;
  parent[0][k] = par;
  level[k] = lvl;
  for (auto it : g[k]) {
    if (it.first == par) continue;
    mx[0][it.first] = it.second;
    dfs(it.first, k, lvl + 1);
  }
  tout[k] = tim;
}
long long walk(long long u, long long h) {
  long long sum = 0;
  for (long long i = LG - 1; i >= 0; i--) {
    if ((h >> i) & 1) {
      sum += mx[i][u];
      u = parent[i][u];
    }
  }
  if (sum != 0) return -1;
  return u;
}
long long walk1(long long u, long long h) {
  long long h1 = h;
  long long sum = 0;
  for (long long i = LG - 1; i >= 0; i--) {
    if ((h >> i) & 1) {
      sum += mx[i][u];
      u = parent[i][u];
    }
  }
  if (sum != h1) return -1;
  return u;
}
void precompute() {
  for (long long i = 1; i < LG; i++)
    for (long long j = 1; j <= n; j++) {
      if (parent[i - 1][j]) parent[i][j] = parent[i - 1][parent[i - 1][j]];
      mx[i][j] = mx[i - 1][j] + mx[i - 1][parent[i - 1][j]];
    }
}
long long LCA(long long u, long long v) {
  if (level[u] < level[v]) swap(u, v);
  long long diff = level[u] - level[v];
  for (long long i = LG - 1; i >= 0; i--) {
    if ((1 << i) & diff) {
      u = parent[i][u];
    }
  }
  if (u == v) return u;
  for (long long i = LG - 1; i >= 0; i--) {
    if (parent[i][u] && parent[i][u] != parent[i][v]) {
      u = parent[i][u];
      v = parent[i][v];
    }
  }
  return parent[0][u];
}
long long dist(long long u, long long v) {
  return level[u] + level[v] - 2 * level[LCA(u, v)];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  vector<long long> roots;
  for (long long i = 1; i <= n; i++) {
    long long a, b;
    cin >> a >> b;
    if (a == -1) {
      roots.emplace_back(i);
      continue;
    }
    g[a].emplace_back(i, b);
    g[i].emplace_back(a, b);
  }
  for (auto &x : roots) dfs(x, 0, 1);
  precompute();
  cin >> q;
  while (q--) {
    long long st;
    cin >> st;
    long long u, v;
    cin >> u >> v;
    if (st == 1) {
      long long diff = level[v] - level[u];
      if (diff <= 0) {
        cout << "NO\n";
        continue;
      }
      long long nn = walk(v, diff);
      if (nn != u) {
        cout << "NO\n";
      } else {
        cout << "YES\n";
      }
    } else {
      if (u == v) {
        cout << "NO\n";
        continue;
      }
      long long w = LCA(u, v);
      if (w == v) {
        cout << "NO\n";
        continue;
      }
      long long diff1 = level[u] - level[w];
      long long nn1 = walk(u, diff1);
      if (nn1 != w) {
        cout << "NO\n";
        continue;
      }
      long long diff2 = level[v] - level[w];
      long long nn2 = walk1(v, diff2);
      if (nn2 != w) {
        cout << "NO\n";
        continue;
      }
      cout << "YES\n";
    }
  }
  return 0;
}
