#include <bits/stdc++.h>
using namespace std;
int f(int x) {
  int ans = 1;
  while (x > 0) {
    if (x % 10) ans *= x % 10;
    x /= 10;
  }
  return ans;
}
const int N = 400100;
const int LG = 19;
int up[N][LG], mx[N][LG], pr[N][LG];
int w[N];
long long sum[N];
int cnt = 1;
void add(int pr, int val) {
  int v = ++cnt;
  w[v] = val;
  up[v][0] = pr;
  mx[v][0] = w[pr];
  for (int i = 1; i < LG; i++) {
    up[v][i] = up[up[v][i - 1]][i - 1];
    mx[v][i] = max(mx[v][i - 1], mx[up[v][i - 1]][i - 1]);
  }
  int good = v;
  for (int i = LG - 1; i >= 0; i--) {
    if (mx[good][i] < w[v]) good = up[good][i];
  }
  good = up[good][0];
  ::pr[v][0] = good;
  sum[v] = sum[good] + w[v];
  for (int i = 1; i < LG; i++) {
    ::pr[v][i] = ::pr[::pr[v][i - 1]][i - 1];
  }
}
int calc(int v, long long x) {
  int v1 = v;
  if (w[v] > x) return 0;
  int ans = 1;
  long long cur = sum[v];
  for (int i = LG - 1; i >= 0; i--) {
    if (pr[v][i] == 0) continue;
    if (sum[pr[v][i]] + x >= sum[v1] + w[pr[v][i]]) {
      ans += (1 << i);
      v = pr[v][i];
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  int last = 0;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      long long p, q;
      cin >> p >> q;
      long long R = p ^ last;
      long long W = q ^ last;
      add(R, W);
    } else {
      long long p, q;
      cin >> p >> q;
      long long R = p ^ last;
      long long X = q ^ last;
      last = calc(R, X);
      cout << last << '\n';
    }
  }
  return 0;
}
