#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& x) {
  cin >> x;
}
template <typename T, typename... Types>
inline void read(T& x, Types&... args) {
  cin >> x;
}
const long long N = 1e5 + 10;
long long p[N];
long long px[N], py[N];
vector<long long> cx[N], cy[N];
long long tempo;
long long stx[N], ndx[N], rootx[N];
long long sty[N], ndy[N], rooty[N];
void dfs(long long u, long long color) {
  stx[u] = tempo++;
  rootx[u] = color;
  for (long long v : cx[u]) dfs(v, color);
  ndx[u] = tempo;
}
void dfs2(long long u, long long color) {
  sty[u] = tempo++;
  rooty[u] = color;
  for (long long v : cy[u]) {
    dfs2(v, color);
  }
  ndy[u] = tempo;
}
int32_t main() {
  long long n;
  cin >> n;
  memset(p, -1, sizeof(p));
  memset(px, -1, sizeof(px));
  memset(py, -1, sizeof(py));
  for (long long i = 0; i < n; i++) {
    long long p1, t1;
    cin >> p1 >> t1;
    if (p1 != -1) {
      p1--;
      p[i] = p1;
      if (t1 == 0)
        cx[p1].push_back(i), px[i] = p1;
      else
        cy[p1].push_back(i), py[i] = p1;
    }
  }
  tempo = 0;
  for (long long i = 0; i < n; i++) {
    if (px[i] == -1) {
      dfs(i, i);
    }
  }
  tempo = 0;
  for (long long i = 0; i < n; i++) {
    if (py[i] == -1) {
      dfs2(i, i);
    }
  }
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long type, u, v;
    cin >> type >> u >> v;
    u--, v--;
    if (u == v) {
      cout << "NO" << endl;
      continue;
    }
    if (type == 1) {
      if (stx[u] <= stx[v] && stx[v] < ndx[u]) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    } else {
      if (py[v] == -1 || stx[v] <= stx[u] && stx[u] < ndx[v])
        cout << "NO" << endl;
      else {
        long long root = rootx[u];
        if (sty[root] <= sty[v] && sty[v] < ndy[root]) {
          cout << "YES" << endl;
        } else if (sty[v] <= sty[u] && sty[u] < ndy[v]) {
          cout << "NO" << endl;
        } else if (stx[rooty[v]] <= stx[u] && stx[u] < ndx[rooty[v]]) {
          cout << "YES" << endl;
        } else {
          cout << "NO" << endl;
        }
      }
    }
  }
}
