#include <bits/stdc++.h>
using namespace std;
int WP[404040][20];
signed long long W[404040][20];
int cnt = 1, last = 0;
int Q;
signed long long p, q;
void solve() {
  int i, j, k, l, r, x, y, t;
  string s;
  for (i = 0; i < (20); i++) {
    W[0][i] = 1LL << 60;
    if (i) W[1][i] = 1LL << 60;
  }
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%" PRId64 "%" PRId64, &t, &p, &q);
    p ^= last;
    q ^= last;
    if (t == 1) {
      cnt++;
      W[cnt][0] = q;
      if (W[cnt][0] <= W[p][0]) {
        WP[cnt][0] = p;
      } else {
        for (i = 19; i >= 0; i--) {
          if (W[WP[p][i]][0] < W[cnt][0]) p = WP[p][i];
        }
        WP[cnt][0] = WP[p][0];
      }
      for (i = 1; i <= 19; i++) {
        WP[cnt][i] = WP[WP[cnt][i - 1]][i - 1];
        W[cnt][i] = min(1LL << 60, W[cnt][i - 1] + W[WP[cnt][i - 1]][i - 1]);
      }
    } else {
      last = 0;
      x = p;
      for (i = 19; i >= 0; i--) {
        if (W[x][i] <= q) {
          last += 1 << i;
          q -= W[x][i];
          x = WP[x][i];
        }
      }
      (void)printf("%d\n", last);
    }
  }
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
