#include <bits/stdc++.h>
long long q_pow(long long x, long long n, long long mod) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = x * ret % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return ret;
}
long long __gcd(long long x, long long y) {
  if (!y) return x;
  return __gcd(y, x % y);
}
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
using namespace std;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 400000 + 50;
long long sum[maxn][20], fa[maxn][20], w[maxn];
int cnt = 1;
void insert(int val, int father) {
  w[++cnt] = val;
  if (w[cnt] <= w[father]) {
    fa[cnt][0] = father;
  } else {
    int tmp = father;
    for (int i = 19; i >= 0; i--) {
      if (w[fa[tmp][i]] < w[cnt]) tmp = fa[tmp][i];
    }
    fa[cnt][0] = fa[tmp][0];
  }
  if (fa[cnt][0] == 0)
    sum[cnt][0] = INF;
  else
    sum[cnt][0] = w[fa[cnt][0]];
  for (int i = 1; i <= 19; i++) {
    fa[cnt][i] = fa[fa[cnt][i - 1]][i - 1];
    if (fa[cnt][i] == 0 || sum[cnt][i - 1] == INF)
      sum[cnt][i] = INF;
    else
      sum[cnt][i] = sum[cnt][i - 1] + sum[fa[cnt][i - 1]][i - 1];
  }
}
long long query(int pos, long long val) {
  long long ans = 0;
  if (val < w[pos]) return 0;
  val -= w[pos], ans++;
  for (int i = 19; i >= 0; i--) {
    if (sum[pos][i] <= val) {
      val -= sum[pos][i];
      ans += (1LL << i);
      pos = fa[pos][i];
    }
  }
  return ans;
}
signed main(int argc, char *argv[]) {
  if (argc == 2 && strcmp("-debug", argv[1]) == 0) {
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
  }
  int n;
  cin >> n;
  long long last = 0;
  memset((sum[1]), (0x3f), sizeof(sum[1]));
  w[0] = INF, w[1] = 0;
  long long opt, x, y;
  for (int i = 1; i <= n; i++) {
    scanf("%lld%lld%lld", &opt, &x, &y);
    x ^= last, y ^= last;
    if (opt == 1) {
      insert(y, x);
    } else {
      last = query(x, y);
      printf("%lld\n", last);
    }
  }
  return 0;
}
