#include <bits/stdc++.h>
using namespace std;
long long y = 2;
long long par[(long long)4e5 + 2][20], w[(long long)4e5 + 2],
    sum[(long long)4e5 + 2][20];
vector<long long> to(20);
long long getpar(long long p) {
  for (int i = 19; i >= 0; i--) {
    if (par[p][i] != -1 && w[par[p][i]] < w[y]) {
      p = par[p][i];
    }
  }
  return p;
}
long long getsum(long long p, long long x) {
  int ans = 0;
  for (int k = 19; k >= 0; k--) {
    if (x >= sum[p][k]) {
      x -= sum[p][k];
      ans += to[k];
      p = par[p][k];
    }
  }
  return ans;
}
void kml(long long j) {
  for (long long k = 1; k < 20; k++) {
    if (par[j][k - 1] != -1) {
      par[j][k] = par[par[j][k - 1]][k - 1];
      sum[j][k] = sum[j][k - 1] + sum[par[j][k - 1]][k - 1];
    }
  }
}
int main() {
  cin.tie();
  ios_base::sync_with_stdio(0);
  to[0] = 1;
  for (long long j = 1; j < 20; j++) to[j] = 2 * to[j - 1];
  long long q;
  long long a, b, l = 0;
  memset(par, -1, sizeof(par));
  for (long long k = 0; k < 4e5 + 2; k++) {
    for (long long j = 0; j < 20; j++) sum[k][j] = 1e17;
  }
  cin >> q;
  w[1] = 0;
  while (q--) {
    long long t;
    cin >> t >> a >> b;
    a = (a ^ l);
    b = (b ^ l);
    if (t == 1) {
      w[y] = b;
      if (b <= w[a]) {
        par[y][0] = a;
      } else {
        long long p = getpar(a);
        par[y][0] = par[p][0];
      }
      if (par[y][0] != -1) sum[y][0] = w[par[y][0]];
      kml(y);
      y++;
    } else {
      if (b < w[a]) {
        cout << 0 << endl;
        l = 0;
      } else {
        b -= w[a];
        l = 1 + getsum(a, b);
        cout << l << endl;
      }
    }
  }
  return 0;
}
