#include <bits/stdc++.h>
using namespace std;
const int maxq = 4e5 + 10, maxn = maxq, oo = 1e9 + 10, maxp = 20;
const long long INF = 1e15 + 10;
int Q, cnt, last, ans;
int w[maxq];
int a[maxn][maxp];
long long sum[maxn][maxp];
int main() {
  int i, j, k, op, R, W, nxt, ai;
  long long p, q, X;
  scanf("%d", &Q);
  w[0] = oo;
  cnt = 1;
  last = 0;
  for (i = (0); i <= (19); i++) {
    sum[1][i] = INF;
  }
  for (; Q--;) {
    scanf("%d%I64d%I64d", &op, &p, &q);
    R = p ^ last;
    if (op == 1) {
      W = q ^ last;
      w[++cnt] = W;
      if (w[R] >= W) {
        a[cnt][0] = R;
      } else {
        nxt = R;
        for (i = 19; i >= 0; i--) {
          if (w[a[nxt][i]] < W) {
            nxt = a[nxt][i];
          }
        }
        a[cnt][0] = a[nxt][0];
      }
      sum[cnt][0] = ((a[cnt][0]) ? w[a[cnt][0]] : INF);
      for (i = (1); i <= (19); i++) {
        a[cnt][i] = a[a[cnt][i - 1]][i - 1];
        sum[cnt][i] =
            ((a[cnt][i]) ? sum[cnt][i - 1] + sum[a[cnt][i - 1]][i - 1] : INF);
      }
    } else {
      X = q ^ last;
      if (w[R] > X) {
        printf("0\n");
        last = 0;
      } else {
        X -= w[R];
        ans = 1;
        ai = R;
        for (i = 19; i >= 0; i--) {
          if (sum[ai][i] <= X) {
            ans += (1 << i);
            X -= sum[ai][i];
            ai = a[ai][i];
          }
        }
        printf("%d\n", ans);
        last = ans;
      }
    }
  }
  return 0;
}
