#include <bits/stdc++.h>
using namespace std;
long long val[1000005];
int cnt;
int par[400002][20];
long long sum[400002][20];
void add(int p, long long w) {
  int node = ++cnt;
  val[node] = w;
  if (val[node] <= val[p]) {
    par[node][0] = p;
  } else {
    int i, flag;
    while (1) {
      flag = 0;
      for (i = 0; i < 20; i++) {
        if (par[p][i] == -1) break;
        if (val[par[p][i]] >= val[node]) {
          flag = 1;
          break;
        }
      }
      if (i == 0) {
        if (val[node] <= val[p]) par[node][0] = p;
        if (flag == 0)
          break;
        else
          par[node][0] = par[p][0];
        break;
      } else {
        p = par[p][i - 1];
      }
    }
  }
  if (par[node][0] != -1) {
    sum[node][0] = val[par[node][0]];
  } else {
    sum[node][0] = 0;
  }
  for (int i = 1; i < 20; i++) {
    if (par[node][i - 1] != -1) {
      par[node][i] = par[par[node][i - 1]][i - 1];
      sum[node][i] = sum[node][i - 1] + sum[par[node][i - 1]][i - 1];
    }
  }
}
long long get_ans(int node, long long x) {
  long long len = 0;
  if (val[node] > x) {
    return len;
  }
  x -= val[node];
  len++;
  for (int i = 20 - 1; i >= 0; i--) {
    if (par[node][i] != -1 && sum[node][i] <= x) {
      x -= sum[node][i];
      node = par[node][i];
      len += (1LL << i);
    }
  }
  return len;
}
int main() {
  int i, j, k, l, m, n, t, r, op;
  int flag = 0;
  long long ans = 0, an = 0;
  t = 1;
  while (t--) {
    int Q;
    long long last = 0, p, q, R, W, X;
    memset(par, -1, sizeof(par));
    scanf("%d", &Q);
    cnt = 1;
    while (Q--) {
      scanf("%d %lld %lld", &op, &p, &q);
      if (op == 1) {
        R = p ^ last;
        W = q ^ last;
        add(R, W);
      } else {
        R = p ^ last;
        X = q ^ last;
        last = get_ans(R, X);
        printf("%d\n", (int)last);
      }
    }
  }
  return 0;
}
