#include <bits/stdc++.h>
using namespace std;
template <class T>
bool remin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool remax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int nxt() {
  int first;
  scanf("%d", &first);
  return first;
}
long long gcd(long long a, long long b) {
  a = abs(a);
  b = abs(b);
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
struct pt {
  long double first, second;
  pt() {}
  pt(long double first, long double second) : first(first), second(second) {}
  inline pt operator-(const pt &r) const {
    return pt(first - r.first, second - r.second);
  }
  inline pt operator+(const pt &r) const {
    return pt(first + r.first, second + r.second);
  }
  inline pt operator*(const long double &r) const {
    return pt(first * r, second * r);
  }
  inline long double sqlen() const {
    return abs(first * first + second * second);
  }
  inline long double len() const { return sqrt(sqlen()); }
  inline bool operator<(const pt &r) const {
    if (first != r.first) return first < r.first;
    return second < r.second;
  }
  inline bool operator==(const pt &r) const {
    return first == r.first && second == r.second;
  }
};
ostream &operator<<(ostream &os, const pt &p) {
  return os << "(" << p.first << "," << p.second << ")";
}
inline long double cross(const pt &l, const pt &r) {
  return l.first * r.second - l.second * r.first;
}
inline long double dot(const pt &l, const pt &r) {
  return l.first * r.first + l.second * r.second;
}
long long pwmod(long long a, long long n, long long mod) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = ret * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ret;
}
template <typename T>
inline T sqr(T first) {
  return first * first;
}
struct DSU {
  vector<int> p;
  vector<int> sz;
  void init(int n) {
    p.resize(n);
    sz.resize(n);
    for (int i = 0; i < (int)(n); i++) {
      p[i] = i;
      sz[i] = 1;
    }
  }
  int get(int v) {
    if (p[v] == v) return v;
    return p[v] = get(p[v]);
  }
  void unite(int a, int b) {
    a = get(a);
    b = get(b);
    if (a == b) return;
    if (sz[a] < sz[b]) swap(a, b);
    p[b] = a;
    sz[a] += sz[b];
  }
};
const int N = 1000 * 100 + 10;
const int LG = 20;
vector<pair<int, int> > g[N];
int up[N][LG];
int ty[N][LG];
int tin[N];
int tout[N];
int timer = 0;
void dfs(int v, int p, int tt = -1) {
  tin[v] = timer++;
  up[v][0] = p;
  ty[v][0] = tt;
  for (int i = 1; i < LG; ++i) {
    up[v][i] = up[up[v][i - 1]][i - 1];
    if (ty[up[v][i - 1]][i - 1] == -1 || ty[v][i - 1] == -1 ||
        ty[v][i - 1] != ty[up[v][i - 1]][i - 1]) {
      ty[v][i] = -1;
    } else {
      ty[v][i] = ty[v][i - 1];
    }
  }
  for (auto pa : g[v]) {
    dfs(pa.first, v, pa.second);
  }
  tout[v] = timer++;
}
inline bool isUpper(int a, int b) {
  return tin[a] <= tin[b] && tout[b] <= tout[a];
}
bool get1(int a, int b) {
  if (a == b) return false;
  if (!isUpper(b, a)) return false;
  for (int i = LG - 1; i >= 0; --i) {
    if (!isUpper(up[a][i], b)) {
      if (ty[a][i] != 0) return false;
      a = up[a][i];
    }
  }
  return ty[a][0] == 0;
}
bool get2(int a, int b) {
  if (a == b) return false;
  if (isUpper(a, b)) return false;
  for (int i = LG - 1; i >= 0; --i) {
    if (!isUpper(up[b][i], a)) {
      if (ty[b][i] != 0) return false;
      b = up[b][i];
    }
  }
  if (!isUpper(b, a)) {
    if (ty[b][0] != 0) return false;
    b = up[b][0];
  }
  for (int i = LG - 1; i >= 0; --i) {
    if (!isUpper(up[a][i], b)) {
      if (ty[a][i] != 1) {
        return false;
      }
      a = up[a][i];
    }
  }
  return ty[a][0] == 1;
}
void solve() {
  int n = nxt();
  DSU dsu;
  dsu.init(n);
  vector<int> roots;
  for (int i = 0; i < (int)(n); i++) {
    int p = nxt();
    int t = nxt();
    if (p != -1) {
      dsu.unite(i, p - 1);
      g[p - 1].push_back(make_pair(i, t));
    } else {
      roots.push_back(i);
    }
  }
  for (int v : roots) {
    timer = 0;
    dfs(v, v);
  }
  int q = nxt();
  for (int i = 0; i < (int)(q); i++) {
    int t = nxt();
    int v = nxt() - 1;
    int u = nxt() - 1;
    if (dsu.get(v) != dsu.get(u)) {
      cout << "NO\n";
      continue;
    }
    bool res;
    if (t == 1) {
      res = get1(u, v);
    } else {
      res = get2(u, v);
    }
    cout << (res ? "YES" : "NO") << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  double cl0 = clock();
  solve();
  cerr << "Time: " << (clock() - cl0) / CLOCKS_PER_SEC << std::endl;
  return 0;
}
