#include <bits/stdc++.h>
using namespace std;
int Q, type, R, cnt = 1, p[400005][20], mu[22], l;
long long d[400005][20], w[400005], X;
void make(int h, int k) {
  while (w[k] < w[h]) {
    k = p[k][0];
  }
  p[h][0] = k;
  if (k != 0) {
    d[h][0] = w[h] + w[k];
    for (int i = 1; i <= 19; ++i) {
      p[h][i] = p[p[h][i - 1]][i - 1];
      d[h][i] = d[h][i - 1] + d[p[h][i - 1]][i - 1] - w[p[h][i - 1]];
    }
  } else
    for (int i = 0; i <= 19; ++i) d[h][i] = 1e16;
}
void GET() {
  int res = 1, last = R;
  long long cur = w[R];
  for (int i = 19; i >= 0; --i)
    if (cur + d[R][i] - w[R] <= X)
      res += mu[i], cur += d[R][i] - w[R], R = p[R][i];
  if (R == last && w[R] > X)
    printf("0\n"), l = 0;
  else
    printf("%d\n", res), l = res;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  scanf("%d", &Q);
  mu[0] = 1;
  w[0] = 1e13;
  for (int i = 0; i <= 19; ++i) d[0][i] = d[1][i] = 1e16;
  for (int i = 1; i <= 20; ++i) mu[i] = mu[i - 1] * 2;
  while (Q) {
    scanf("%d%d%lld", &type, &R, &X);
    R = R ^ l;
    X = X ^ l;
    if (type == 1) {
      w[++cnt] = X;
      make(cnt, R);
    } else {
      GET();
    }
    Q--;
  }
}
