#include <bits/stdc++.h>
const bool DEBUG = false;
using namespace std;
const long long maxn = 4e5 + 5;
const long long INF = 4e18;
const long long M = 1e9 + 7;
const int lg = 22;
long long x, last, cnt, w[maxn], sum[lg][maxn], seq[lg][maxn];
long long q;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> q;
  cnt = 2;
  for (int i = 0; i < maxn; i++)
    for (int j = 0; j < lg; j++) sum[j][i] = seq[j][i] = -1;
  sum[0][1] = 0;
  while (q--) {
    long long tp, P, Q;
    cin >> tp >> P >> Q;
    if (tp == 1) {
      long long R = last ^ P, W = last ^ Q, v = cnt, vp = R;
      w[v] = W;
      sum[0][v] = W;
      if (w[R] >= W)
        seq[0][v] = R;
      else {
        for (int i = lg - 1; i >= 0; i--) {
          long long x = seq[i][vp];
          if (x != -1 and w[x] < W) {
            vp = x;
          }
        }
        seq[0][v] = seq[0][vp];
      }
      for (int i = 1; i < lg; i++) {
        long long x = seq[i - 1][v];
        if (x != -1) {
          seq[i][v] = seq[i - 1][x];
          if (sum[i - 1][x] != -1) sum[i][v] = sum[i - 1][v] + sum[i - 1][x];
        }
      }
      cnt++;
    } else {
      long long ans = 0, t = 0, first = Q ^ last, v = last ^ P;
      for (int i = lg - 1; i >= 0; i--) {
        if (v != -1 and sum[i][v] != -1 and sum[i][v] + ans <= first) {
          t += (1 << i);
          ans += sum[i][v];
          v = seq[i][v];
        }
      }
      last = t;
      cout << t << endl;
    }
  }
  return 0;
}
