#include <bits/stdc++.h>
using namespace std;
long long log2n = 19, cnt = 1;
long long anc[400010][20], maxv[400010][20], v[400010];
long long anc2[400010][20], sum[400010][20];
long long pow2[] = {1,     2,     4,     8,      16,     32,    64,
                    128,   256,   512,   1024,   2048,   4096,  8192,
                    16384, 32768, 65536, 131072, 262144, 524288};
long long Q, last;
int main() {
  long long i, idx, p, q, t, ans;
  v[0] = 1e15 + 1;
  for (i = 0; i <= log2n; i++)
    maxv[1][i] = maxv[0][i] = sum[1][i] = sum[0][i] = 1e15 + 1;
  scanf("%lld", &Q);
  while (Q--) {
    scanf("%lld%lld%lld", &idx, &p, &q);
    p ^= last;
    q ^= last;
    if (idx == 1) {
      v[++cnt] = q;
      anc[cnt][0] = p;
      maxv[cnt][0] = v[anc[cnt][0]];
      for (i = 1; i <= log2n; i++) {
        anc[cnt][i] = anc[anc[cnt][i - 1]][i - 1];
        maxv[cnt][i] = max(maxv[cnt][i - 1], maxv[anc[cnt][i - 1]][i - 1]);
      }
      for (t = cnt, i = log2n; i >= 0; i--)
        if (maxv[t][i] < v[cnt]) t = anc[t][i];
      anc2[cnt][0] = anc[t][0];
      sum[cnt][0] = v[anc2[cnt][0]];
      for (i = 1; i <= log2n; i++) {
        anc2[cnt][i] = anc2[anc2[cnt][i - 1]][i - 1];
        sum[cnt][i] = sum[cnt][i - 1] + sum[anc2[cnt][i - 1]][i - 1];
      }
    } else {
      q -= v[p];
      ans = 1;
      if (q < 0) {
        ans = 0;
        goto xxx;
      }
      for (t = p, i = log2n; i >= 0; i--)
        if (sum[t][i] <= q) {
          q -= sum[t][i];
          ans += pow2[i];
          t = anc2[t][i];
        }
    xxx:
      last = ans;
      printf("%lld\n", ans);
    }
  }
  return 0;
}
