#include <bits/stdc++.h>
using namespace std;
const int dydis = 4e5 + 10;
const int dd = 20;
const int non = dydis - 1;
long long sm[dydis][dd];
int kur[dydis][dd];
int tevas[dydis];
long long we[dydis];
int nxt[dydis];
int dbInd = 2;
int he[dydis];
void prd(int pr, long long w) {
  int v = dbInd++;
  tevas[v] = pr;
  we[v] = w;
  int u = pr;
  while (true) {
    if (we[u] >= we[v]) {
      nxt[v] = u;
      he[v] = he[u] + 1;
      break;
    }
    if (nxt[u] == u) {
      nxt[v] = 1;
      he[v] = he[0] + 1;
      break;
    }
    u = nxt[u];
  }
  kur[v][0] = nxt[v];
  for (int i = 1; i < dd; i++) {
    kur[v][i] = kur[kur[v][i - 1]][i - 1];
  }
  sm[v][0] = we[v];
  for (int i = 1; i < dd; i++) {
    sm[v][i] = sm[v][i - 1] + sm[kur[v][i - 1]][i - 1];
  }
}
int fd(int v, long long s) {
  if (we[v] > s) {
    return 0;
  }
  int vv = v;
  int ret = 1;
  for (int i = dd - 1; i > -1; i--) {
    if (sm[v][i] <= s) {
      s -= sm[v][i];
      v = kur[v][i];
      ret = max(ret, he[vv] - he[v]);
    }
  }
  return ret;
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  tevas[1] = 0;
  he[1] = 1;
  we[1] = 0;
  he[0] = 0;
  we[0] = 0;
  for (int i = 0; i < dd; i++) {
    kur[1][i] = 0;
    sm[1][i] = 0;
    kur[0][i] = 0;
    sm[0][i] = 0;
  }
  int q;
  cin >> q;
  int last = 0;
  while (q--) {
    int type;
    cin >> type;
    long long p, q;
    cin >> p >> q;
    if (type == 1) {
      long long S = p ^ last, W = q ^ last;
      prd(S, W);
    } else {
      long long S = p ^ last;
      long long X = q ^ last;
      long long ans = fd(S, X);
      last = ans;
      cout << last << "\n";
    }
  }
  return 0;
}
