#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
const long long INFL = 1e18 + 123;
const double PI = atan2(0, -1);
mt19937 tw(960172);
long long rnd(long long x, long long y) {
  static uniform_int_distribution<long long> d;
  return d(tw) % (y - x + 1) + x;
}
const int MAXN = 1e5 + 5;
vector<pair<int, int> > graph1[MAXN];
int ans[MAXN];
bool used[MAXN];
const int bp = 20;
int binup[bp][MAXN];
int depth[MAXN];
int color[MAXN], len[MAXN];
int type[MAXN];
int dfs(int v, int p, int d, int c, int t) {
  used[v] = true;
  type[v] = t;
  depth[v] = d;
  binup[0][v] = p;
  color[v] = c;
  if (color[p] == color[v]) {
    len[v] = len[p] + 1;
  } else {
    len[v] = 1;
  }
  for (int i = 1; i < bp; ++i) {
    binup[i][v] = binup[i - 1][binup[i - 1][v]];
  }
  for (pair<int, int> to : graph1[v]) {
    if (to.first != p) {
      dfs(to.first, v, d + 1, to.second, t);
    }
  }
  return 0;
}
int get_lca(int a, int b) {
  if (depth[a] > depth[b]) {
    swap(a, b);
  }
  for (int i = bp - 1; i >= 0; --i) {
    if (depth[a] + (1 << i) <= depth[b]) {
      b = binup[i][b];
    }
  }
  if (a == b) {
    return a;
  }
  for (int i = bp - 1; i >= 0; --i) {
    if (binup[i][a] != binup[i][b]) {
      a = binup[i][a];
      b = binup[i][b];
    }
  }
  return binup[0][a];
}
int main() {
  cerr << fixed << setprecision(15);
  cout << fixed << setprecision(15);
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int p, t;
    scanf("%d%d", &p, &t);
    --p;
    if (t == 0) {
      graph1[i].push_back({p, 0});
      graph1[p].push_back({i, 1});
    } else if (t == 1) {
      graph1[p].push_back({i, 0});
      graph1[i].push_back({p, 1});
    }
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (!used[i]) {
      dfs(i, i, 0, 0, cnt);
      ++cnt;
    }
  }
  int q;
  scanf("%d", &q);
  vector<pair<int, int> > inp;
  for (int i = 0; i < q; ++i) {
    int t, u, v;
    scanf("%d%d%d", &t, &u, &v);
    --u;
    --v;
    if (t == 1) {
      if (type[u] == type[v]) {
        int lca = get_lca(u, v);
        bool flag =
            (lca == u && color[v] == 1 && len[v] >= depth[v] - depth[lca]);
        ans[i] = flag;
      }
    } else {
      if (type[u] == type[v]) {
        int lca = get_lca(u, v);
        bool flag = true;
        if (lca != u) {
          flag &= (color[u] == 1 && len[u] >= depth[u] - depth[lca]);
        }
        flag &= (v != lca && color[v] == 0 && len[v] >= depth[v] - depth[lca]);
        ans[i] = flag;
      }
    }
    inp.push_back({u, v});
  }
  for (int i = 0; i < q; ++i) {
    if (ans[i] && inp[i].first != inp[i].second) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}
