#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return a * (b / gcd(a, b));
}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
vector<int> v[100001];
int parent[100001][17], b[100001][17], depth[100001];
void dfs(int N, int p, int d) {
  depth[N] = d;
  for (int next : v[N]) {
    if (next == p) continue;
    dfs(next, N, d + 1);
  }
}
int LCA(int x, int y) {
  if (depth[x] < depth[y]) swap(x, y);
  int dif = depth[x] - depth[y];
  for (int j = 0; dif > 0; j++) {
    if (dif & 1) x = parent[x][j];
    dif /= 2;
  }
  if (x != y) {
    for (int(j) = (16); (j) >= (0); (j) -= (1)) {
      if (parent[x][j] != -1 && parent[x][j] != parent[y][j]) {
        x = parent[x][j];
        y = parent[y][j];
      }
    }
    x = parent[x][0];
  }
  return x;
}
int query1(int u, int x) {
  int d = depth[x] - depth[u];
  int c = 0;
  for (int(j) = (16); (j) >= (0); (j) -= (1)) {
    if (d & (1 << j)) {
      c |= b[x][j];
      x = parent[x][j];
    }
  }
  return c == 1;
}
int query2(int u, int x) {
  int d = depth[x] - depth[u];
  int c = 0;
  for (int(j) = (16); (j) >= (0); (j) -= (1)) {
    if (d & (1 << j)) {
      c |= b[x][j];
      x = parent[x][j];
    }
  }
  return c == 2;
}
int p[100001];
int find(int a) {
  if (p[a] < 0) return a;
  return p[a] = find(p[a]);
}
void merge(int a, int b) {
  a = find(a), b = find(b);
  if (a != b) {
    p[b] = a;
  }
}
int main() {
  memset((p), -1, sizeof(p));
  ;
  memset((parent), -1, sizeof(parent));
  ;
  int n;
  scanf("%d", &n);
  vector<int> R;
  for (int(i) = (1); (i) <= (n); (i) += (1)) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (x == -1)
      R.push_back(i);
    else {
      merge(i, x);
      parent[i][0] = x;
      v[i].push_back(x);
      v[x].push_back(i);
      b[i][0] = 1 << y;
    }
  }
  for (auto r : R) dfs(r, -1, 0);
  for (int(j) = (0); (j) <= (15); (j) += (1))
    for (int(i) = (1); (i) <= (n); (i) += (1))
      if (parent[i][j] != -1) {
        parent[i][j + 1] = parent[parent[i][j]][j];
        b[i][j + 1] = b[i][j] | b[parent[i][j]][j];
      }
  int q;
  scanf("%d", &q);
  while (q--) {
    int o, x, y;
    scanf("%d%d%d", &o, &x, &y);
    if (find(x) != find(y)) {
      puts("NO");
      continue;
    }
    int u = LCA(x, y);
    bool res = 0;
    if (o == 1) {
      if (u == x && query1(u, y)) res = 1;
    } else {
      if (u == x) {
        if (query2(u, y)) res = 1;
      } else {
        if (query1(u, x) && query2(u, y)) res = 1;
      }
    }
    puts(res ? "YES" : "NO");
  }
}
