#include <bits/stdc++.h>
using namespace std;
long long int parsum[400005][20];
long long int par[400005][20];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int q;
  cin >> q;
  long long int last = 0;
  long long int curr = 2;
  par[2][0] = 1;
  while (q--) {
    long long int op, p, q;
    cin >> op >> p >> q;
    if (op == 1) {
      curr++;
      long long int r = p xor last;
      long long int w = q xor last;
      r++;
      parsum[curr][0] = w;
      par[curr][0] = r;
      while (parsum[par[curr][0]][0] < parsum[curr][0] and par[curr][0] > 1)
        par[curr][0] = par[par[curr][0]][0];
      for (long long int i = 1; i < 20; i++) {
        par[curr][i] = par[par[curr][i - 1]][i - 1];
        parsum[curr][i] = parsum[par[curr][i - 1]][i - 1] + parsum[curr][i - 1];
      }
    } else {
      long long int r = p xor last;
      r++;
      long long int x = q xor last;
      long long int res = 0;
      for (long long int i = 19; i >= 0; i--) {
        if (par[r][i] and parsum[r][i] <= x) {
          x -= parsum[r][i];
          r = par[r][i];
          res += (1 << i);
        }
      }
      cout << res << "\n";
      last = res;
    }
  }
  return 0;
}
