#include <bits/stdc++.h>
using namespace std;
const long long maxn = 400010, inf = 1e18;
long long q, lastans, cnt = 1, w[maxn];
long long fa[maxn][21], sum[maxn][21];
void add(long long x, long long v) {
  w[++cnt] = v;
  if (w[cnt] <= w[x])
    fa[cnt][0] = x;
  else {
    int y = x;
    for (int i = 20; i >= 0; i--) {
      if (w[fa[y][i]] < w[cnt]) y = fa[y][i];
    }
    fa[cnt][0] = fa[y][0];
  }
  if (fa[cnt][0] == 0)
    sum[cnt][0] = inf;
  else
    sum[cnt][0] = w[fa[cnt][0]];
  for (int i = 1; i <= 20; i++) {
    fa[cnt][i] = fa[fa[cnt][i - 1]][i - 1];
    if (fa[cnt][i] == 0)
      sum[cnt][i] = inf;
    else
      sum[cnt][i] = sum[cnt][i - 1] + sum[fa[cnt][i - 1]][i - 1];
  }
}
long long query(long long x, long long v) {
  if (w[x] > v) return 0;
  v -= w[x];
  long long res = 1;
  for (int i = 20; i >= 0; i--) {
    if (v >= sum[x][i]) {
      v -= sum[x][i];
      res += (1 << i);
      x = fa[x][i];
    }
  }
  return res;
}
int main() {
  w[0] = inf;
  for (int i = 0; i <= 20; i++) sum[1][i] = inf;
  scanf("%lld", &q);
  while (q--) {
    int id;
    long long a, b;
    scanf("%d", &id);
    scanf("%lld%lld", &a, &b);
    a ^= lastans;
    b ^= lastans;
    if (id == 1)
      add(a, b);
    else
      printf("%lld\n", lastans = query(a, b));
  }
}
