#include <bits/stdc++.h>
using namespace std;
int n, p[(100010)], t[(100010)], q, be[(100010)], ed[(100010)], tt;
int fa[(100010)][(22)], fb[(100010)][(22)];
vector<int> v[(100010)];
void dfs(int x, int fa) {
  be[x] = ++tt;
  for (auto it = v[x].begin(); it != v[x].end(); ++it) {
    int y = *it;
    if (y != fa) {
      dfs(y, x);
    }
  }
  ed[x] = tt;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", p + i, t + i);
    fa[i][0] = fb[i][0] = i;
    if (p[i] != -1) {
      v[p[i]].push_back(i);
      if (t[i] == 1) {
        fa[i][0] = p[i];
      } else {
        fb[i][0] = p[i];
      }
    }
  }
  for (int i = 1; i <= 20; ++i) {
    for (int j = 1; j <= n; ++j) {
      fa[j][i] = fa[fa[j][i - 1]][i - 1];
      fb[j][i] = fb[fb[j][i - 1]][i - 1];
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (p[i] == -1) {
      dfs(i, 0);
    }
  }
  scanf("%d", &q);
  while (q--) {
    int t, x, y;
    scanf("%d%d%d", &t, &x, &y);
    if (x == y) {
      printf("NO\n");
      continue;
    }
    int ans = 0;
    if (t == 1) {
      for (int i = 20; ~i; --i) {
        if ((be[x] < be[fb[y][i]] && ed[x] >= ed[fb[y][i]])) {
          y = fb[y][i];
        }
      }
      ans = fb[y][0] == x;
    } else {
      if (!(be[x] < be[y] && ed[x] >= ed[y])) {
        for (int i = 20; ~i; --i) {
          if (!(be[fb[x][i]] < be[y] && ed[fb[x][i]] >= ed[y])) {
            x = fb[x][i];
          }
        }
        x = fb[x][0];
      }
      if ((be[x] < be[y] && ed[x] >= ed[y])) {
        for (int i = 20; ~i; --i) {
          if ((be[x] < be[fa[y][i]] && ed[x] >= ed[fa[y][i]])) {
            y = fa[y][i];
          }
        }
        ans = fa[y][0] == x;
      }
    }
    printf("%s\n", ans ? "YES" : "NO");
  }
}
