#include <bits/stdc++.h>
using namespace std;
int Q, k, last, n = 1;
int fa[400005][20], Max[400005][20];
int F[400005][20];
int a[400005];
long long sum[400005][20];
long long p, q;
void add(int x, long long p) {
  n++;
  fa[n][0] = x, a[n] = p;
  Max[n][0] = a[x];
  for (int i = 1; 1 << i <= n; i++) fa[n][i] = fa[fa[n][i - 1]][i - 1];
  for (int i = 1; 1 << i <= n; i++)
    Max[n][i] = max(Max[n][i - 1], Max[fa[n][i - 1]][i - 1]);
  int f = n;
  for (int i = 19; i >= 0; i--)
    if (fa[f][i] && Max[f][i] < p) f = fa[f][i];
  f = fa[f][0];
  F[n][0] = f;
  sum[n][0] = a[F[n][0]];
  for (int i = 1; 1 << i <= n; i++) F[n][i] = F[F[n][i - 1]][i - 1];
  for (int i = 1; 1 << i <= n; i++)
    sum[n][i] = sum[n][i - 1] + sum[F[n][i - 1]][i - 1];
}
int query(int x, long long p) {
  if (a[x] > p) return 0;
  long long s = a[x];
  int cnt = 1;
  for (int i = 19; i >= 0; i--) {
    if (F[x][i] && sum[x][i] + s <= p) {
      s += sum[x][i];
      x = F[x][i];
      cnt += 1 << i;
    }
  }
  return cnt;
}
int main() {
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    scanf("%d%lld%lld", &k, &p, &q);
    if (k == 1)
      add(p ^ last, q ^ last);
    else {
      last = query(p ^ last, q ^ last);
      printf("%d\n", last);
    }
  }
}
