#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const double pi = acos(-1.0), eps = 1e-9;
const int N = 4e5 + 111, inf = 1e9, mod = 1e9 + 7;
struct query {
  int t;
  long long x, w, r;
} q[N];
long long last = 0, mx[21][N], w[N], sum[21][N];
int n, cnt = 1, p[21][N], pa[21][N];
int getmx(int x) {
  int y = p[0][x];
  for (int j = 20; j >= 0; --j) {
    if (mx[j][y] < w[x]) y = p[j][y];
  }
  return y;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d%I64d", &q[i].t, &q[i].r);
    q[i].r ^= last;
    if (q[i].t == 1) {
      scanf("%I64d", &q[i].w);
      q[i].w ^= last;
      ++cnt;
      p[0][cnt] = q[i].r;
      mx[0][cnt] = q[i].w;
      w[cnt] = q[i].w;
      for (int j = 1; j <= 20; ++j) {
        p[j][cnt] = p[j - 1][p[j - 1][cnt]];
        mx[j][cnt] = max(mx[j - 1][cnt], mx[j - 1][p[j - 1][cnt]]);
      }
      int x = getmx(cnt);
      sum[0][cnt] = w[cnt];
      pa[0][cnt] = x;
      for (int j = 1; j <= 20; ++j) {
        pa[j][cnt] = pa[j - 1][pa[j - 1][cnt]];
        sum[j][cnt] = sum[j - 1][cnt] + sum[j - 1][pa[j - 1][cnt]];
      }
    } else {
      scanf("%I64d", &q[i].x);
      q[i].x ^= last;
      int x = q[i].r;
      long long ans = 0;
      for (int j = 20; j >= 0; --j)
        if (pa[j][x] && q[i].x >= sum[j][x]) {
          ans += (1 << j);
          q[i].x -= sum[j][x];
          x = pa[j][x];
        }
      if (q[i].x >= sum[0][x]) ans++;
      last = ans;
      printf("%I64d\n", ans);
    }
  }
  return 0;
}
