#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
int n = 1, Q, opt;
int st[maxn][23], fa[maxn][23], bl[maxn][23];
long long sum[maxn][23], u, v, last;
int go(int pos, long long w) {
  pos = fa[pos][0];
  for (int i = 21; i >= 0; i--)
    if (st[pos][i] < w) pos = fa[pos][i];
  return pos;
}
int calc(int pos, long long w) {
  int ret = 0;
  for (int i = 21; i >= 0; i--) {
    if (bl[pos][i] && sum[pos][i] <= w) {
      w -= sum[pos][i];
      pos = bl[pos][i];
      ret += (1 << i);
    }
  }
  if (w >= sum[pos][0]) ret++;
  return ret;
}
int main() {
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d %lld %lld", &opt, &u, &v);
    u ^= last, v ^= last;
    if (opt == 1) {
      fa[++n][0] = u;
      st[n][0] = v;
      sum[n][0] = v;
      for (int i = 1; i <= 21; i++) {
        fa[n][i] = fa[fa[n][i - 1]][i - 1];
        st[n][i] = max(st[n][i - 1], st[fa[n][i - 1]][i - 1]);
      }
      bl[n][0] = go(n, v);
      for (int i = 1; i <= 21; i++) {
        bl[n][i] = bl[bl[n][i - 1]][i - 1];
        sum[n][i] = sum[n][i - 1] + sum[bl[n][i - 1]][i - 1];
      }
    } else
      printf("%d\n", last = calc(u, v));
  }
  return 0;
}
