#include <bits/stdc++.h>
using namespace std;
int nxt[400005][21];
int maxi[400005][21];
long long sum[400005][21];
int get_nxt(int parent, int val) {
  if (maxi[parent][20] < val) {
    return -1;
  }
  for (int i = 20; i >= 0; i--) {
    if (maxi[parent][i] < val) {
      parent = nxt[parent][i];
    }
  }
  return parent;
}
int get_ans(int node, long long val) {
  int ans = 0;
  for (int i = 20; i > 0; i--) {
    if (nxt[node][i] == -1) continue;
    if (sum[node][i] <= val) {
      val -= sum[node][i];
      node = nxt[node][i];
      ans += 1 << i;
    }
  }
  while (node != -1) {
    if (sum[node][0] <= val) {
      val -= sum[node][0];
      node = nxt[node][0];
      ans++;
    } else
      break;
  }
  return ans;
}
int main() {
  int Q, c;
  long long p, q;
  cin >> Q;
  int last = 0, cnt = 2;
  for (int i = 0; i <= 20; i++) {
    nxt[1][i] = -1;
  }
  while (Q--) {
    scanf("%d %lld %lld", &c, &p, &q);
    p ^= last;
    q ^= last;
    if (c == 1) {
      int next = get_nxt(p, q);
      nxt[cnt][0] = next;
      for (int i = 1; i <= 20; i++) {
        if (nxt[cnt][i - 1] == -1)
          nxt[cnt][i] = -1;
        else
          nxt[cnt][i] = nxt[nxt[cnt][i - 1]][i - 1];
      }
      maxi[cnt][0] = q;
      for (int i = 1; i <= 20; i++) {
        if (nxt[cnt][i - 1] == -1)
          maxi[cnt][i] = maxi[cnt][i - 1];
        else
          maxi[cnt][i] = max(maxi[cnt][i - 1], maxi[nxt[cnt][i - 1]][i - 1]);
      }
      sum[cnt][0] = q;
      for (int i = 1; i <= 20; i++) {
        if (nxt[cnt][i - 1] == -1)
          sum[cnt][i] = sum[cnt][i - 1];
        else
          sum[cnt][i] = sum[cnt][i - 1] + sum[nxt[cnt][i - 1]][i - 1];
      }
      cnt++;
    } else {
      int ans = get_ans(p, q);
      last = ans;
      printf("%d\n", ans);
    }
  }
  return 0;
}
