#include <bits/stdc++.h>
using namespace std;
const int N = 400004;
const int L = 20;
int up[N][L];
int mx[N][L];
int up1[N][L];
long long sum[N][L];
int sz;
int a[N];
int closest(int v, int val) {
  for (int i = L - 1; i >= 0; --i) {
    if (up[v][i] == 0) continue;
    if (mx[v][i] < val) v = up[v][i];
  }
  if (a[v] < val) {
    if (up[v][0] != 0 && a[up[v][0]] >= val)
      v = up[v][0];
    else
      return 0;
  }
  return v;
}
void add(int v, int val) {
  ++sz;
  up[sz][0] = v;
  mx[sz][0] = val;
  a[sz] = val;
  for (int i = 1; i < L; ++i) {
    up[sz][i] = up[up[sz][i - 1]][i - 1];
    mx[sz][i] = max(mx[sz][i - 1], mx[up[sz][i - 1]][i - 1]);
  }
  up1[sz][0] = closest(v, val);
  sum[sz][0] = val;
  for (int i = 1; i < L; ++i) {
    up1[sz][i] = up1[up1[sz][i - 1]][i - 1];
    sum[sz][i] = sum[sz][i - 1] + sum[up1[sz][i - 1]][i - 1];
  }
}
long long cnt[L + 1];
int get(int v, long long val) {
  int ans = 0;
  for (int i = L - 1; i >= 0; --i) {
    if (up1[v][i] == 0) continue;
    if (sum[v][i] <= val) {
      val -= sum[v][i];
      v = up1[v][i];
      ans += cnt[i];
    }
  }
  if (a[v] <= val) ++ans;
  return ans;
}
long long n, first, second, z;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  sz = 1;
  cnt[0] = 1;
  for (int i = 1; i < L; ++i) cnt[i] = cnt[i - 1] * 2;
  cin >> n;
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    cin >> first >> second >> z;
    second ^= res;
    z ^= res;
    if (first == 1) {
      add(second, z);
    } else {
      res = get(second, z);
      printf("%d\n", res);
    }
  }
}
