#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long int binsum[400001][20];
long long int bin[400001][20] = {{0}};
long long int wt[400001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int i, j;
  for (i = 0; i <= 400000; i++) {
    for (j = 0; j <= 19; j++) {
      binsum[i][j] = 1e15 + 1;
    }
  }
  wt[0] = 1e15;
  wt[1] = 0;
  long long int last = 0;
  long long int cnt = 2;
  long long int qq;
  cin >> qq;
  while (qq--) {
    long long int type;
    cin >> type;
    if (type == 1) {
      long long int p, q;
      cin >> p >> q;
      long long int r = p ^ last, w = q ^ last;
      wt[cnt] = w;
      if (wt[r] >= wt[cnt]) {
        bin[cnt][0] = r;
      } else {
        for (i = 19; i >= 0; i--) {
          if (wt[bin[r][i]] < wt[cnt]) r = bin[r][i];
        }
        bin[cnt][0] = bin[r][0];
      }
      binsum[cnt][0] = wt[bin[cnt][0]];
      for (i = 1; i <= 19; i++) {
        bin[cnt][i] = bin[bin[cnt][i - 1]][i - 1];
        binsum[cnt][i] = binsum[cnt][i - 1] + binsum[bin[cnt][i - 1]][i - 1];
      }
      cnt++;
    } else {
      long long int p, q;
      cin >> p >> q;
      long long int r, x;
      r = p ^ last, x = q ^ last;
      if (wt[r] > x) {
        cout << 0 << "\n";
        last = 0;
        continue;
      } else {
        long long int ans = 1;
        x -= wt[r];
        for (i = 19; i >= 0; i--) {
          if (binsum[r][i] <= x) {
            ans += 1 << i;
            x -= binsum[r][i];
            r = bin[r][i];
          }
        }
        cout << ans << "\n";
        last = ans;
      }
    }
  }
}
