#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e5 + 5;
int n;
int parent[MAXN];
long long value[MAXN];
int nxt[MAXN];
long long jump[21][MAXN], jumpSum[21][MAXN];
void update(int x) {
  if (value[parent[x]] >= value[x]) {
    nxt[x] = parent[x];
  } else if (jump[0][parent[x]] == 0) {
    nxt[x] = 0;
  } else {
    int y = parent[x];
    for (int i = 20; i >= 0; i--) {
      if (jump[i][y] == 0) continue;
      if (value[jump[i][y]] < value[x]) {
        y = jump[i][y];
      }
    }
    nxt[x] = nxt[y];
    if (value[nxt[x]] < value[x]) nxt[x] = 0;
  }
  jump[0][x] = nxt[x];
  jumpSum[0][x] = value[nxt[x]];
  for (int i = 1; i <= 20; i++) {
    jump[i][x] = jump[i - 1][x];
    if (jump[i][x] != 0) {
      jump[i][x] = jump[i - 1][jump[i - 1][x]];
      jumpSum[i][x] = jumpSum[i - 1][x] + jumpSum[i - 1][jump[i - 1][x]];
    } else {
      jumpSum[i][x] = jumpSum[i - 1][x];
    }
  }
}
int query(int u, long long x) {
  int answer = 0;
  long long sum = 0;
  for (int i = 20; i >= 0; i--) {
    if (jump[i][u] == 0) continue;
    if (jumpSum[i][u] + sum <= x) {
      answer += (1 << i);
      sum += jumpSum[i][u];
      u = jump[i][u];
    }
  }
  return answer;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int Q;
  int type;
  long long p, q;
  int newNode = 2;
  long long last = 0;
  cin >> Q;
  while (Q--) {
    cin >> type;
    cin >> p >> q;
    if (type == 1) {
      long long R = p ^ last;
      long long W = q ^ last;
      value[newNode] = W;
      parent[newNode] = R;
      update(newNode);
      newNode++;
    } else {
      long long R = p ^ last;
      long long X = q ^ last;
      if (value[R] > X) {
        last = 0;
      } else {
        last = 1 + query(R, X - value[R]);
      }
      cout << last << '\n';
    }
  }
}
