#include <bits/stdc++.h>
const long long N = 4e5 + 10;
long long fa[N][21] = {0}, sum[N][21], cnt = 0, last = 0, x, y, Q, op, w[N];
void add(long long u, long long val) {
  cnt++;
  w[cnt] = val;
  if (w[u] >= val)
    fa[cnt][0] = u;
  else {
    for (int i = 20; i >= 0; i--) {
      if (w[fa[u][i]] < w[cnt]) u = fa[u][i];
    }
    fa[cnt][0] = fa[u][0];
  }
  if (fa[cnt][0] == 0)
    sum[cnt][0] = 1e18;
  else
    sum[cnt][0] = w[fa[cnt][0]];
  for (int i = 1; i <= 20; i++) {
    fa[cnt][i] = fa[fa[cnt][i - 1]][i - 1];
    if (fa[cnt][i] == 0)
      sum[cnt][i] = 1e18;
    else
      sum[cnt][i] = sum[fa[cnt][i - 1]][i - 1] + sum[cnt][i - 1];
  }
}
long long query(long long u, long long val) {
  if (w[u] > val) return 0;
  long long ans = 1;
  val -= w[u];
  for (int i = 20; i >= 0; i--) {
    if (sum[u][i] <= val) {
      val -= sum[u][i];
      u = fa[u][i];
      ans += (1 << i);
    }
  }
  return ans;
}
int main() {
  w[0] = 1e18;
  w[1] = 0;
  cnt = 1;
  scanf("%lld", &Q);
  for (int i = 0; i <= 20; i++) sum[1][i] = 1e18;
  while (Q--) {
    scanf("%lld %lld %lld", &op, &x, &y);
    x ^= last;
    y ^= last;
    if (op == 1)
      add(x, y);
    else {
      printf("%lld\n", last = query(x, y));
    }
  }
}
