#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5e5 + 113;
long long pr[maxn][25];
long long sumpr[maxn][25];
long long vess[maxn];
long long pred[maxn];
void updver(long long pf, long long ves, long long v) {
  vess[v] = ves;
  if (vess[pf] >= vess[v])
    pr[v][0] = pf, sumpr[v][0] = vess[v];
  else {
    for (long long i = 21; i >= 0; i--) {
      if (!pr[pf][i]) continue;
      if (vess[pr[pf][i]] < vess[v]) pf = pr[pf][i];
    }
    pf = pr[pf][0];
    if (vess[pf] >= vess[v]) pr[v][0] = pf;
    sumpr[v][0] = vess[v];
  }
  for (long long i = 0; i <= 20; i++) {
    long long df = pr[v][i];
    if (df != 0) {
      pr[v][i + 1] = pr[pr[v][i]][i];
      if (sumpr[pr[v][i]][i] != -1 && sumpr[v][i] != -1)
        sumpr[v][i + 1] = sumpr[v][i] + sumpr[pr[v][i]][i];
    } else
      break;
  }
}
long long ansf(long long v, long long x) {
  if (vess[v] > x) return 0;
  long long ans = 0;
  long long sum = 0;
  for (long long i = 21; i >= 0; i--) {
    if (v == 0) break;
    if (sumpr[v][i] != -1) {
      if (sumpr[v][i] + sum <= x) {
        sum += sumpr[v][i];
        ans += (1 << i);
        v = pr[v][i];
      }
    }
  }
  return ans;
}
int main() {
  srand(time(NULL));
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long q;
  cin >> q;
  vess[1] = 0;
  long long cnt = 2;
  long long last = 0;
  for (long long i = 1; i <= q + 113; i++)
    for (long long j = 0; j <= 23; j++) sumpr[i][j] = -1;
  sumpr[1][0] = 0;
  for (long long i = 0; i < q; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    long long r = (b ^ last);
    long long w = (c ^ last);
    if (a == 1)
      updver(r, w, cnt++);
    else {
      last = ansf(r, w);
      cout << last << "\n";
    }
  }
}
