#include <bits/stdc++.h>
using namespace std;
int st[500100], pr[400100][20], cur, deep[400100], mx[400100][20],
    pr2[400100][20], deep2[400100];
long long w[500100], sum[400100], sum2[400100][20];
int getv(int v, long long x) {
  for (int i = st[deep[v]]; i >= 0; i--) {
    int need = pr[v][i];
    if (need != 0 && sum2[need][0] < x) v = need;
  }
  return v;
}
int get2(int v, long long x) {
  for (int i = st[deep[v]]; i >= 0; i--) {
    int need = pr[v][i];
    if (need != 0 && sum[need] - sum2[need][0] >= x) v = need;
  }
  return v;
}
void link(int v, int prr, long long x) {
  deep[v] = deep[prr] + 1;
  sum[v] = sum[prr] + x;
  sum2[v][0] = x;
  pr[v][0] = prr;
  for (int i = 1; i <= st[deep[v]]; i++) {
    pr[v][i] = pr[pr[v][i - 1]][i - 1];
    sum2[v][i] = sum2[v][i - 1] + sum2[pr[v][i - 1]][i - 1];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  st[1] = 0;
  for (int i = 1; i <= 500000; i++) st[i] = st[i / 2] + 1;
  cur = 1;
  link(1, 0, 0);
  int tt;
  cin >> tt;
  long long lst = 0;
  while (tt--) {
    int type;
    long long a, b;
    cin >> type >> a >> b;
    a ^= lst;
    b ^= lst;
    if (type == 1) {
      ++cur;
      int v = getv(a, b);
      if (sum2[v][0] < b) v = pr[v][0];
      link(cur, v, b);
    } else {
      long long sm = sum[a] - b;
      long long v = get2(a, sm);
      long long ans = deep[a] - deep[v] + 1;
      if (sum2[a][0] > b) ans = 0;
      lst = ans;
      cout << ans << "\n";
    }
  }
}
