#include <bits/stdc++.h>
using namespace std;
const long long N = 4e5 + 7, M = 20;
long long p[N][M], lvl[N], val[N], sum[N][M];
void update(long long v, long long u) {
  p[v][0] = u;
  lvl[v] = lvl[u] + 1;
  for (long long i = 1; i < M; i++) {
    p[v][i] = p[p[v][i - 1]][i - 1];
  }
  sum[v][0] = val[v];
  for (long long i = 1; i < M; i++) {
    sum[v][i] = sum[v][i - 1] + sum[p[v][i - 1]][i - 1];
  }
}
long long find(long long x, long long l) {
  for (long long i = M - 1; i >= 0; i--) {
    if (lvl[x] - (1LL << i) >= l) {
      x = p[x][i];
    }
  }
  return x;
}
long long query(long long x, long long l) {
  long long s = 0;
  for (long long i = M - 1; i >= 0; i--) {
    if (lvl[x] - (1LL << i) >= l) {
      s += sum[x][i];
      x = p[x][i];
    }
  }
  return s + sum[x][0];
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long cnt = 1, lst = 0;
  update(1, 1);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    long long typ, p, q;
    cin >> typ >> p >> q;
    p ^= lst;
    q ^= lst;
    if (typ == 1) {
      ++cnt;
      long long l = 1, r = lvl[p], ans = cnt;
      while (l <= r) {
        long long mid = (l + r) >> 1;
        long long k = find(p, mid);
        if (val[k] >= q)
          ans = k, l = mid + 1;
        else
          r = mid - 1;
      }
      val[cnt] = q;
      update(cnt, ans);
    } else {
      long long l = 1, r = lvl[p], ans = 0;
      while (l <= r) {
        long long mid = (l + r) >> 1;
        long long k = query(p, mid);
        if (k <= q)
          r = mid - 1, ans = lvl[p] - mid + 1;
        else
          l = mid + 1;
      }
      cout << ans << "\n";
      lst = ans;
    }
  }
}
