#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > adj[100001];
vector<int> val(100001, 0);
vector<int> lev(100001, 0);
vector<vector<int> > table(100001, vector<int>(20, -1));
vector<int> vis(100001, 0);
int n, level;
int counti = 1;
void dfs(int i) {
  vis[i] = counti;
  for (int j = 0; j < adj[i].size(); j++) {
    table[adj[i][j].first][0] = i;
    lev[adj[i][j].first] = lev[i] + 1;
    val[adj[i][j].first] = val[i] + adj[i][j].second;
    dfs(adj[i][j].first);
  }
}
void preprocess() {
  for (int i = 1; i <= level; i++) {
    for (int j = 1; j <= n; j++) {
      if (table[j][i - 1] != -1) table[j][i] = table[table[j][i - 1]][i - 1];
    }
  }
}
int lcs(int x, int y) {
  if (lev[x] < lev[y]) swap(x, y);
  int diff = lev[x] - lev[y];
  while (diff > 0) {
    int k = log2(diff);
    x = table[x][k];
    k = 1 << k;
    diff -= k;
  }
  if (x == y) return y;
  for (int j = level; j >= 0; j--) {
    if (table[x][j] != -1 && table[x][j] != table[y][j]) {
      x = table[x][j];
      y = table[y][j];
    }
  }
  return table[x][0];
}
int main() {
  int root;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x, y;
    cin >> x >> y;
    if (x == -1) {
      continue;
    }
    if (y == 0) {
      adj[x].push_back(make_pair(i, 1));
    } else if (y == 1) {
      adj[x].push_back(make_pair(i, -1));
    } else
      adj[x].push_back(make_pair(i, 0));
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      dfs(i);
      counti++;
    }
  }
  level = log2(n);
  preprocess();
  int q;
  cin >> q;
  while (q--) {
    int p, x, y;
    cin >> p >> x >> y;
    if (vis[x] != vis[y] || x == y) {
      cout << "NO" << endl;
      continue;
    }
    int l = lcs(x, y);
    if (l == x) {
      int p1 = lev[y] - lev[l];
      if (p == 1 && p1 == (val[y] - val[l])) {
        cout << "YES" << endl;
      } else if (p == 2 && p1 == -1 * (val[y] - val[l])) {
        cout << "YES" << endl;
      } else
        cout << "NO" << endl;
    } else if (l == y) {
      cout << "NO" << endl;
    } else {
      int p1 = lev[y] - lev[l];
      int p2 = lev[x] - lev[l];
      if (p == 2 && p1 == -1 * (val[y] - val[l]) && p2 == (val[x] - val[l])) {
        cout << "YES" << endl;
      } else
        cout << "NO" << endl;
    }
  }
  return 0;
}
