#include <bits/stdc++.h>
using namespace std;
const int M = 400005, LOGM = 22;
int Q, t, last, cur, A[M], fa[LOGM][M], ans;
long long sum[LOGM][M], p, q;
int Up(int k) {
  for (int i = 19; i >= 0; i--) {
    if (A[fa[i][k]] < A[cur]) k = fa[i][k];
  }
  return k;
}
int main() {
  A[0] = 1e9;
  cur = 1;
  scanf("%d", &Q);
  for (int i = 0; i < LOGM; i++) sum[i][1] = 1e17;
  while (Q--) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%I64d%I64d", &p, &q);
      p ^= last;
      q ^= last;
      cur++;
      A[cur] = q;
      if (A[p] >= A[cur]) {
        fa[0][cur] = p;
      } else {
        fa[0][cur] = fa[0][Up(p)];
      }
      sum[0][cur] = (fa[0][cur] == 0 ? 1e17 : A[fa[0][cur]]);
      for (int i = 1; i < LOGM; i++) {
        fa[i][cur] = fa[i - 1][fa[i - 1][cur]];
        sum[i][cur] =
            (fa[i][cur] == 0 ? 1e17
                             : sum[i - 1][cur] + sum[i - 1][fa[i - 1][cur]]);
      }
    } else {
      scanf("%I64d%I64d", &p, &q);
      p ^= last;
      q ^= last;
      if (A[p] > q) {
        puts("0");
        last = 0;
      } else {
        q -= A[p];
        ans = 1;
        for (int i = 19; i >= 0; i--) {
          if (sum[i][p] <= q) {
            ans += (1 << i);
            q -= sum[i][p];
            p = fa[i][p];
          }
        }
        printf("%d\n", ans);
        last = ans;
      }
    }
  }
  return 0;
}
