#include <bits/stdc++.h>
using namespace std;
long long father[400010][20];
long long biggest[400010][20];
long long idbig[400010][20];
long long wbig[400010][20];
long long w[400010];
long long h[400010];
void add_node(long long nod, long long _w, long long tata) {
  w[nod] = _w;
  h[nod] = 1 + h[tata];
  wbig[nod][0] = _w;
  father[nod][0] = tata;
  for (int i(1); i < 20; i++)
    father[nod][i] = father[father[nod][i - 1]][i - 1];
  biggest[nod][0] = nod;
  for (int i(1); i < 20; i++) {
    long long x = biggest[nod][i - 1], y = biggest[father[nod][i - 1]][i - 1];
    if (w[x] >= w[y])
      biggest[nod][i] = x;
    else
      biggest[nod][i] = y;
  }
  long long big(tata);
  for (int i(19); i >= 0; i--)
    if (w[biggest[big][i]] < w[nod]) big = father[big][i];
  idbig[nod][0] = big;
  wbig[nod][0] = w[nod];
  for (int i(1); i < 20; i++) {
    idbig[nod][i] = idbig[idbig[nod][i - 1]][i - 1];
    wbig[nod][i] = wbig[nod][i - 1] + wbig[idbig[nod][i - 1]][i - 1];
  }
}
long long find_lant(long long nod, long long x) {
  long long ans(0);
  for (int i(19); i >= 0; i--) {
    if (idbig[nod][i] && x >= wbig[nod][i]) {
      x -= wbig[nod][i], nod = idbig[nod][i], ans += (1 << i);
    }
  }
  if (x >= w[nod]) ans++;
  return ans;
}
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  add_node(1, 0, 0);
  long long q, cnt = 1;
  long long last(0);
  cin >> q;
  while (q--) {
    long long op, r, x;
    cin >> op >> r >> x;
    r ^= last;
    x ^= last;
    if (op == 1) {
      add_node(++cnt, x, r);
    } else {
      last = find_lant(r, x);
      cout << last << '\n';
    }
  }
  return 0;
}
