#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
const int up = 20;
const long long inf = 1e18;
int tot, m;
long long last, p, q;
long long w[N], s[N][25];
int fat[N][25];
void add(int p, int q) {
  w[++tot] = q;
  if (w[tot] <= w[p]) {
    fat[tot][0] = p;
  } else {
    for (int j = up; j >= 0; j--) {
      if (w[fat[p][j]] < w[tot]) p = fat[p][j];
    }
    fat[tot][0] = fat[p][0];
  }
  if (fat[tot][0] == 0) {
    s[tot][0] = inf;
  } else {
    s[tot][0] = w[fat[tot][0]];
  }
  for (int j = 1; j <= 20; j++) {
    fat[tot][j] = fat[fat[tot][j - 1]][j - 1];
    s[tot][j] =
        fat[tot][j] == 0 ? inf : s[tot][j - 1] + s[fat[tot][j - 1]][j - 1];
  }
}
long long query(int v, long long sum) {
  long long ans = 0;
  if (sum >= w[v]) {
    sum -= w[v];
    ans++;
    for (int j = 20; j >= 0; j--) {
      if (s[v][j] <= sum) {
        ans += (1 << j);
        sum -= s[v][j];
        v = fat[v][j];
      }
    }
  }
  return ans;
}
int main() {
  w[0] = inf;
  tot = 1;
  scanf("%d", &m);
  memset(s[1], 0x7f, sizeof(s[1]));
  while (m--) {
    int op;
    scanf("%d%lld%lld", &op, &p, &q);
    p ^= last, q ^= last;
    if (op == 1)
      add(p, q);
    else
      printf("%d\n", last = query(p, q));
  }
  return 0;
}
