#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
long long stable[N][20];
void update(int i) {
  for (int j = 1; j < 20; j++) {
    stable[i][j] = stable[stable[i][j - 1]][j - 1];
  }
}
int getpth(int x, int y) {
  if (!y) return stable[x][0];
  for (int i = 0; i < 20; i++) {
    if ((1 << i) & y) x = stable[x][i];
  }
  return x;
}
long long w[N], accsum[N] = {0};
int lvl[N] = {0};
int main() {
  int q, cntr = 1;
  long long x, y, z, last = 0;
  w[0] = 1e18;
  w[1] = 0;
  lvl[1] = 1;
  scanf("%d", &q);
  while (q--) {
    scanf("%lld%lld%lld", &x, &y, &z);
    y ^= last, z ^= last;
    if (x == 1) {
      cntr++;
      w[cntr] = z;
      if (w[y] >= w[cntr])
        stable[cntr][0] = y;
      else {
        int low = 0, high = N, mid;
        while (low < high) {
          mid = (low + high) / 2;
          int parent = getpth(y, mid);
          if (w[parent] < w[cntr])
            low = mid + 1;
          else
            high = mid;
        }
        stable[cntr][0] = getpth(y, high);
      }
      update(cntr);
      accsum[cntr] = w[cntr];
      if (stable[cntr][0]) {
        accsum[cntr] += accsum[stable[cntr][0]];
      }
      lvl[cntr] = lvl[stable[cntr][0]] + 1;
    } else {
      if (w[y] > z) {
        last = 0;
        puts("0");
        continue;
      }
      int low = 0, high = lvl[y] + 1, mid;
      while (low < high) {
        mid = (low + high + 1) / 2;
        int parent = getpth(y, mid);
        if (accsum[y] - accsum[parent] > z)
          high = mid - 1;
        else
          low = mid;
      }
      int parent = getpth(y, high);
      last = lvl[y] - lvl[parent];
      printf("%d\n", last);
    }
  }
  return 0;
}
