#include <bits/stdc++.h>
namespace fastIO {
bool IOerror = 0;
inline char nc() {
  static char buf[100000], *p1 = buf + 100000, *pend = buf + 100000;
  if (p1 == pend) {
    p1 = buf;
    pend = buf + fread(buf, 1, 100000, stdin);
    if (pend == p1) {
      IOerror = 1;
      return -1;
    }
  }
  return *p1++;
}
inline bool blank(char ch) {
  return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
inline void read(int &x) {
  char ch;
  while (blank(ch = nc()))
    ;
  if (IOerror) return;
  for (x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0')
    ;
}
};  // namespace fastIO
template <class T>
inline T lowbit(T x) {
  return x & (-x);
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
template <class T>
inline bool scan(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF) return 0;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return 1;
}
const double pi = 3.14159265358979323846264338327950288L;
using namespace std;
const long long mod = 1000000007;
const int DEG = 20;
struct Edge {
  int to, next, w;
} edge[100005 * 2];
int head[100005], tot, indegree[100005];
int n, q, root;
void add_edge(int u, int v, int w) {
  edge[tot].to = v;
  edge[tot].w = w;
  edge[tot].next = head[u];
  head[u] = tot++;
}
void init() {
  tot = 0;
  memset(head, -1, sizeof head);
  memset(indegree, 0, sizeof(indegree));
}
int fa[100005][DEG];
int deg[100005];
int dis[100005];
void BFS() {
  queue<int> que;
  for (int root = 1; root <= n; root++)
    if (!indegree[root]) {
      deg[root] = 0;
      fa[root][0] = root;
      que.push(root);
      dis[root] = 0;
    }
  while (!que.empty()) {
    int tmp = que.front();
    que.pop();
    for (int i = 1; i < DEG; i++) fa[tmp][i] = fa[fa[tmp][i - 1]][i - 1];
    for (int i = head[tmp]; i != -1; i = edge[i].next) {
      int v = edge[i].to;
      if (v == fa[tmp][0]) continue;
      deg[v] = deg[tmp] + 1;
      dis[v] = dis[tmp] + edge[i].w;
      fa[v][0] = tmp;
      que.push(v);
    }
  }
}
int father[100005];
int Find(int x) {
  return x == father[x] ? father[x] : father[x] = Find(father[x]);
}
int LCA(int u, int v) {
  if (deg[u] > deg[v]) swap(u, v);
  int hu = deg[u], hv = deg[v];
  int tu = u, tv = v;
  for (int det = hv - hu, i = 0; det; det >>= 1, i++)
    if (det & 1) tv = fa[tv][i];
  if (tu == tv) return tu;
  for (int i = DEG - 1; i >= 0; i--) {
    if (fa[tu][i] == fa[tv][i]) continue;
    tu = fa[tu][i];
    tv = fa[tv][i];
  }
  return fa[tu][0];
}
void solve() {
  int type, u, v;
  cin >> type >> u >> v;
  if (Find(u) != Find(v) || u == v) {
    printf("NO\n");
    return;
  }
  int lca = LCA(u, v);
  if (v == lca) {
    printf("NO\n");
    return;
  }
  if (type == 1) {
    if (u == lca && deg[v] - deg[u] == dis[v] - dis[u]) {
      printf("YES\n");
    } else
      printf("NO\n");
  } else {
    if (2 * (deg[v] - deg[lca]) == dis[v] - dis[lca] &&
        deg[u] - deg[lca] == dis[u] - dis[lca]) {
      printf("YES\n");
    } else
      printf("NO\n");
  }
}
int main() {
  cin >> n;
  init();
  for (int i = 1; i <= n; i++) father[i] = i;
  for (int i = 1; i <= n; i++) {
    int fa, type;
    cin >> fa >> type;
    if (fa == -1) continue;
    if (!type) {
      add_edge(fa, i, 1);
    } else {
      add_edge(fa, i, 2);
    }
    indegree[i]++;
    int p1 = Find(fa), p2 = Find(i);
    if (p1 != p2) {
      father[p2] = p1;
    }
  }
  BFS();
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
