#include <bits/stdc++.h>
using namespace std;
template <typename T>
void printvec(vector<T>& vec) {
  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i] << " ";
  }
  cout << "\n";
}
vector<vector<long long> > par(400000, vector<long long>(20, -1)),
    sum(400000, vector<long long>(20, 1e18));
vector<long long> cost(400000);
long long ctr = 1;
bool flag = false;
void addnode(long long curr, long long prev) {
  long long i;
  if (cost[prev] >= cost[curr]) {
    par[curr][0] = prev;
  } else {
    int a = prev;
    for (i = 19; i >= 0; i--) {
      if (cost[par[a][i]] < cost[curr]) {
        a = par[a][i];
      }
      par[curr][0] = par[a][0];
    }
  }
  sum[curr][0] = cost[curr];
  for (i = 1; i < 20; i++) {
    if (par[curr][i - 1] != -1)
      par[curr][i] = par[par[curr][i - 1]][i - 1];
    else
      par[curr][i] = -1;
    if (par[curr][i - 1] != -1)
      sum[curr][i] = sum[curr][i - 1] + sum[par[curr][i - 1]][i - 1];
  }
}
long long querynode(long long curr, long long maxw) {
  long long i;
  if (maxw < cost[curr]) return 0;
  long long ans = 0;
  for (i = 19; i >= 0; i--) {
    if (curr != -1 && maxw >= sum[curr][i]) {
      maxw -= sum[curr][i];
      curr = par[curr][i];
      ans += (1LL << i);
    }
  }
  return ans;
}
int main() {
  std::ios::sync_with_stdio(false);
  int ttt = 1;
  while (ttt--) {
    long long q, n, i;
    sum[0][0] = 0;
    cin >> q;
    long long last = 0;
    for (long long iii = 0; iii < q; iii++) {
      if (iii == 1) flag = true;
      long long a, b, c;
      cin >> a >> b >> c;
      if (a == 1) {
        long long r, w;
        r = b ^ last;
        w = c ^ last;
        r--;
        cost[ctr] = w;
        addnode(ctr++, r);
      } else {
        long long r, x;
        r = b ^ last;
        x = c ^ last;
        r--;
        last = querynode(r, x);
        cout << last << "\n";
      }
    }
  }
  return 0;
}
