#include <bits/stdc++.h>
template <typename T>
class IntegerIterator
    : public std::iterator<std::input_iterator_tag, T, std::ptrdiff_t, T*, T> {
 public:
  explicit IntegerIterator(T value) : value(value) {}
  IntegerIterator& operator++() {
    ++value;
    return *this;
  }
  IntegerIterator operator++(int) {
    IntegerIterator copy = *this;
    ++value;
    return copy;
  }
  IntegerIterator& operator--() {
    --value;
    return *this;
  }
  IntegerIterator operator--(int) {
    IntegerIterator copy = *this;
    --value;
    return copy;
  }
  T operator*() const { return value; }
  bool operator==(IntegerIterator rhs) const { return value == rhs.value; }
  bool operator!=(IntegerIterator rhs) const { return !(*this == rhs); }

 private:
  T value;
};
template <typename T>
class IntegerRange {
 public:
  IntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }
  IntegerIterator<T> begin() const { return IntegerIterator<T>(begin_); }
  IntegerIterator<T> end() const { return IntegerIterator<T>(end_); }

 private:
  T begin_;
  T end_;
};
template <typename T>
class ReversedIntegerRange {
 public:
  ReversedIntegerRange(T begin, T end) : begin_(begin), end_(end) { ; }
  std::reverse_iterator<IntegerIterator<T>> begin() const {
    return std::reverse_iterator<IntegerIterator<T>>(
        IntegerIterator<T>(begin_));
  }
  std::reverse_iterator<IntegerIterator<T>> end() const {
    return std::reverse_iterator<IntegerIterator<T>>(IntegerIterator<T>(end_));
  }

 private:
  T begin_;
  T end_;
};
template <typename T>
IntegerRange<T> range(T to) {
  return IntegerRange<T>(0, to);
}
template <typename T>
IntegerRange<T> range(T from, T to) {
  return IntegerRange<T>(from, to);
}
template <typename T>
IntegerRange<T> inclusiveRange(T to) {
  return IntegerRange<T>(0, to + 1);
}
template <typename T>
IntegerRange<T> inclusiveRange(T from, T to) {
  return IntegerRange<T>(from, to + 1);
}
template <typename T>
ReversedIntegerRange<T> downrange(T from) {
  return ReversedIntegerRange<T>(from, 0);
}
template <typename T>
ReversedIntegerRange<T> downrange(T from, T to) {
  return ReversedIntegerRange<T>(from, to);
}
template <typename T>
ReversedIntegerRange<T> inclusiveDownrange(T from) {
  return ReversedIntegerRange<T>(from + 1, 0);
}
template <typename T>
ReversedIntegerRange<T> inclusiveDownrange(T from, T to) {
  return ReversedIntegerRange<T>(from + 1, to);
}
using namespace std;
class TaskD {
 public:
  void solve(std::istream& in, std::ostream& out) {
    int n;
    in >> n;
    vector<vector<int>> parents_parts(17, vector<int>(n));
    vector<vector<int>> parents_cs(17, vector<int>(n));
    vector<int> top_parts(n);
    vector<int> top_cs(n);
    vector<int> depth(n);
    for (int i : range(n)) {
      int pr, tp;
      in >> pr >> tp;
      --pr;
      if (tp == -1) {
        parents_cs[0][i] = i;
        parents_parts[0][i] = i;
        top_parts[i] = 0;
        top_cs[i] = 0;
        depth[i] = 0;
        continue;
      }
      depth[i] = depth[pr] + 1;
      if (tp == 0) {
        parents_cs[0][i] = pr;
        parents_parts[0][i] = i;
        top_cs[i] = top_cs[pr];
        top_parts[i] = depth[i];
      } else {
        parents_cs[0][i] = i;
        parents_parts[0][i] = pr;
        top_cs[i] = depth[i];
        top_parts[i] = top_parts[pr];
      }
    }
    for (int i : range(16)) {
      for (int j : range(n)) {
        parents_cs[i + 1][j] = parents_cs[i][parents_cs[i][j]];
        parents_parts[i + 1][j] = parents_parts[i][parents_parts[i][j]];
      }
    }
    int q;
    in >> q;
    for (int iter : range(q)) {
      int t, u, v;
      in >> t >> u >> v;
      if (u == v) {
        out << "NO\n";
        continue;
      }
      --u, --v;
      if (t == 1) {
        int need_up = depth[v] - depth[u];
        if (need_up < 0) {
          out << "NO\n";
          continue;
        }
        for (int i : downrange(17)) {
          if (need_up & (1 << i)) {
            v = parents_cs[i][v];
          }
        }
        if (v == u) {
          out << "YES\n";
        } else {
          out << "NO\n";
        }
      } else {
        int dep = max(top_cs[u], top_parts[v]);
        int need_u_up = depth[u] - dep;
        int need_v_up = depth[v] - dep;
        if (need_u_up < 0 || need_v_up <= 0) {
          out << "NO\n";
          continue;
        }
        for (int i : downrange(17)) {
          if (need_u_up & (1 << i)) {
            u = parents_cs[i][u];
          }
          if (need_v_up & (1 << i)) {
            v = parents_parts[i][v];
          }
        }
        if (v == u) {
          out << "YES\n";
        } else {
          out << "NO\n";
        }
      }
    }
  }
};
int main() {
  std::ios_base::sync_with_stdio(false);
  TaskD solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  in.tie(nullptr);
  out << std::fixed;
  out.precision(20);
  solver.solve(in, out);
  return 0;
}
