#include <bits/stdc++.h>
using namespace std;
clock_t start;
void Time(bool timeIt) {
  if (!timeIt) return;
  clock_t end = clock();
  double elapsed_time = ((double)end - (double)start) / (double)CLOCKS_PER_SEC;
  printf("Time elapsed = %0.4lf\n", elapsed_time);
}
int cnt = 1;
long long mx[400010][20], sum[400010][20], W[400010];
int nxt[400010][20], par[400010][20], d[400010] = {0};
void addVertex(long long r, long long wt) {
  ++cnt;
  int u = r;
  d[cnt] = d[r] + 1;
  W[cnt] = wt;
  par[cnt][0] = r;
  mx[cnt][0] = wt;
  for (int i = 1; i < 20; ++i) {
    par[cnt][i] = par[par[cnt][i - 1]][i - 1];
    mx[cnt][i] = max(mx[cnt][i - 1], mx[par[cnt][i - 1]][i - 1]);
  }
  while (W[u] < wt) {
    int temp = u;
    bool present = false;
    for (int i = 0; i < 20; ++i) {
      if (mx[u][i] >= wt) {
        present = true;
        break;
      }
      temp = par[u][i];
    }
    if (!present) {
      u = 0;
      break;
    }
    u = temp;
  }
  nxt[cnt][0] = u;
  sum[cnt][0] = wt;
  for (int i = 1; i < 20; ++i) {
    nxt[cnt][i] = nxt[nxt[cnt][i - 1]][i - 1];
    sum[cnt][i] = sum[cnt][i - 1] + sum[nxt[cnt][i - 1]][i - 1];
  }
}
long long query(long long r, long long x) {
  long long ret = 0;
  for (int i = 20 - 1; i >= 0; --i) {
    if (sum[r][i] >= (long long)1e16) continue;
    if (sum[r][i] <= x) {
      ret += (1 << i);
      x -= sum[r][i];
      r = nxt[r][i];
    }
  }
  return ret;
}
int main() {
  start = clock();
  for (int i = 0; i < 400010; ++i) {
    for (int j = 0; j < 20; ++j) {
      par[i][j] = nxt[i][j] = 0;
      mx[i][j] = sum[i][j] = 0;
    }
  }
  for (int i = 1; i < 20; ++i) sum[1][i] = sum[0][i] = (long long)1e16;
  sum[0][0] = (long long)1e16;
  int Q;
  scanf("%d", &Q);
  long long last = 0;
  while (Q--) {
    long long t, r, x;
    scanf("%lld %lld %lld", &t, &r, &x);
    r ^= last;
    x ^= last;
    if (t == 1)
      addVertex(r, x);
    else
      printf("%lld\n", last = query(r, x));
  }
  Time(false);
  return 0;
}
