#include <bits/stdc++.h>
const long long INF = 1e18;
using namespace std;
int fa[20][400005], cnt = 1, Q, x;
long long y, z, a[400005], sum[20][400005], last = 0;
void add(long long r, long long w) {
  a[++cnt] = w;
  if (a[cnt] <= a[r])
    fa[0][cnt] = r;
  else {
    for (int i = 19; i >= 0; i--)
      if (a[fa[i][r]] < a[cnt]) r = fa[i][r];
    fa[0][cnt] = fa[0][r];
  }
  sum[0][cnt] = a[fa[0][cnt]];
  for (int i = 1; i < 20; i++) {
    fa[i][cnt] = fa[i - 1][fa[i - 1][cnt]];
    if (fa[i][cnt] == 0)
      sum[i][cnt] = INF;
    else
      sum[i][cnt] = sum[i - 1][cnt] + sum[i - 1][fa[i - 1][cnt]];
  }
}
long long Query(long long r, long long w) {
  if (a[r] > w) return 0;
  w -= a[r];
  long long ans = 1;
  for (int i = 19; i >= 0; i--)
    if (sum[i][r] <= w) w -= sum[i][r], ans += (1 << i), r = fa[i][r];
  return ans;
}
int main() {
  a[0] = INF, a[1] = 0;
  scanf("%d", &Q);
  for (int i = 0; i <= 19; i++) sum[i][1] = INF, fa[i][1] = 0;
  while (Q--) {
    scanf("%d%lld%lld", &x, &y, &z);
    long long R = y ^ last;
    long long W = z ^ last;
    if (x == 1)
      add(R, W);
    else {
      last = Query(R, W);
      printf("%lld\n", last);
    }
  }
  return 0;
}
