#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int Q;
  cin >> Q;
  int K = 20;
  vvec<int> par(K, vec<int>(Q, -1));
  vvec<int> ma(K, vec<int>(Q, -1));
  vvec<int> f(K, vec<int>(Q, -1));
  vvec<ll> sum(K, vec<ll>(Q, 0));
  vec<int> W(Q);
  int last = 0;
  auto get_query = [&](ll p, ll q) -> pair<int, ll> {
    return {(p ^ last) - 1, q ^ last};
  };
  auto add = [&](int v, int w, int p) {
    par[0][v] = p;
    ma[0][v] = W[p];
    for (int k = 1; k < K; k++) {
      int ne = par[k - 1][v];
      if (ne == -1) continue;
      par[k][v] = par[k - 1][ne];
      ma[k][v] = max(ma[k - 1][v], ma[k - 1][ne]);
    }
    int cur = v;
    for (int k = K - 1; k >= 0; k--)
      if (par[k][cur] != -1) {
        if (ma[k][cur] < w) {
          cur = par[k][cur];
        }
      }
    f[0][v] = par[0][cur];
    W[v] = w;
    sum[0][v] = (f[0][v] == -1 ? 0 : W[f[0][v]]);
    for (int k = 1; k < K; k++) {
      int ne = f[k - 1][v];
      if (ne == -1) continue;
      f[k][v] = f[k - 1][ne];
      sum[k][v] = sum[k - 1][v] + sum[k - 1][ne];
    }
  };
  auto calc = [&](int v, ll x) {
    if (W[v] > x) return 0;
    int c = 1;
    int cur = v;
    x -= W[cur];
    for (int k = K - 1; k >= 0; k--)
      if (f[k][cur] != -1) {
        if (sum[k][cur] > x) continue;
        c += 1 << k;
        x -= sum[k][cur];
        cur = f[k][cur];
      }
    return c;
  };
  int c = 0;
  for (int _ = 0; _ < Q; _++) {
    ll t, p, q;
    cin >> t >> p >> q;
    auto [v, w] = get_query(p, q);
    if (t == 1) {
      c++;
      add(c, w, v);
    } else {
      last = calc(v, w);
      cout << last << "\n";
    }
  }
}
