#include <bits/stdc++.h>
using namespace std;
long long q;
long long cnt;
long long p[400004][21];
long long sum[400004][21];
long long w[400004];
const long long INF = 1e15;
void add_node(long long r, long long x) {
  cnt++;
  w[cnt] = x;
  if (w[r] >= w[cnt]) {
    p[cnt][0] = r;
  } else {
    long long y = r;
    for (long long i = 19; i >= 0; i--) {
      if (w[p[y][i]] < w[cnt]) {
        y = p[y][i];
      }
    }
    p[cnt][0] = p[y][0];
  }
  sum[cnt][0] = w[p[cnt][0]];
  for (long long i = 1; i < 20; i++) {
    p[cnt][i] = p[p[cnt][i - 1]][i - 1];
    sum[cnt][i] = sum[cnt][i - 1] + sum[p[cnt][i - 1]][i - 1];
    if (sum[cnt][i] >= INF) sum[cnt][i] = INF;
  }
}
long long qry(long long r, long long x) {
  long long rem = x;
  if (w[r] > x) {
    return 0;
  }
  rem -= w[r];
  long long y = r;
  long long ans = 1;
  for (long long i = 19; i >= 0; i--) {
    if (sum[y][i] <= rem) {
      rem -= sum[y][i];
      ans = (ans + (1LL << i));
      y = p[y][i];
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> q;
  cnt = 1;
  w[1] = 0;
  long long last = 0;
  w[0] = INF;
  for (long long i = 0; i < 20; i++) {
    sum[1][i] = INF;
  }
  while (q--) {
    long long t, r, x;
    cin >> t >> r >> x;
    r ^= last;
    x ^= last;
    if (t == 1) {
      add_node(r, x);
    } else {
      long long ans = qry(r, x);
      last = ans;
      cout << last << endl;
    }
  }
  return 0;
}
