#include <bits/stdc++.h>
using namespace std;
const int N = 400010;
long long p[N][20], a[N][20], val[N];
void add(int r, int c) {
  for (int i = 19; i > 0; i--) {
    if (p[r][i] <= 0) continue;
    if (val[p[r][i]] < val[c]) r = p[p[r][i]][1];
  }
  if (val[r] < val[c] && p[r][1] > 0) r = p[r][1];
  p[c][0] = c;
  a[c][0] = val[c];
  if (r <= 0 || val[r] < val[c]) return;
  p[c][1] = r;
  a[c][1] = val[r] + val[c];
  for (int i = 2; i < 20; i++) {
    if (p[c][i - 1] <= 0) continue;
    r = p[p[c][i - 1]][1];
    if (r <= 0) continue;
    p[c][i] = p[r][i - 1];
    a[c][i] = a[c][i - 1] + a[r][i - 1];
  }
}
int main() {
  long long c = 1, q, id, r, x, ans = 0;
  memset(p, -1, sizeof p);
  p[1][0] = 1;
  cin >> q;
  while (q--) {
    scanf("%lld %lld %lld", &id, &r, &x);
    r ^= ans;
    x ^= ans;
    if (id == 1) {
      c++;
      val[c] = x;
      add(r, c);
    } else {
      ans = 0;
      for (int i = 19; i >= 0; i--) {
        if (r <= 0 || p[r][i] <= 0 || a[r][i] > x) continue;
        ans += (1 << i);
        x -= a[r][i];
        r = p[p[r][i]][1];
      }
      printf("%lld\n", ans);
    }
  }
  return 0;
}
