#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 400007;
const int MAXL = 21;
int q;
int qtp, qp, qa;
long long qq, qb;
int lans;
int lca[MAXN][MAXL], lmax[MAXN][MAXL], lup[MAXN][MAXL];
long long ups[MAXN][MAXL];
void init();
void input();
void inputq();
void work();
int main() {
  init();
  input();
  work();
}
void init() { ios::sync_with_stdio(false); }
void input() { scanf("%d", &q); }
void inputq() {
  scanf("%d%d%I64d", &qtp, &qp, &qq);
  qa = qp ^ lans, qb = qq ^ lans;
}
void work() {
  memset(lca, -1, sizeof(lca));
  memset(lup, -1, sizeof(lup));
  lmax[1][0] = 0;
  ups[1][0] = 0;
  int vc = 1, nu;
  lans = 0;
  int ans, cur;
  for (int _q = 0; _q < q; ++_q) {
    inputq();
    if (qtp == 1) {
      ++vc;
      lca[vc][0] = qa;
      lmax[vc][0] = static_cast<int>(qb);
      for (int i = 1; i < MAXL; ++i)
        if (~lca[vc][i - 1])
          lca[vc][i] = lca[lca[vc][i - 1]][i - 1],
          lmax[vc][i] = (((lmax[vc][i - 1]) > (lmax[lca[vc][i - 1]][i - 1]))
                             ? (lmax[vc][i - 1])
                             : (lmax[lca[vc][i - 1]][i - 1]));
      nu = qa;
      for (int i = MAXL - 1; i >= 0; --i) {
        if ((~lca[nu][i]) && (lmax[nu][i] < qb)) nu = lca[nu][i];
      }
      if (lmax[nu][0] < qb) nu = lca[nu][0];
      lup[vc][0] = nu;
      ups[vc][0] = qb;
      for (int i = 1; i < MAXL; ++i)
        if (~lup[vc][i - 1])
          lup[vc][i] = lup[lup[vc][i - 1]][i - 1],
          ups[vc][i] = ups[vc][i - 1] + ups[lup[vc][i - 1]][i - 1];
    } else {
      cur = qa;
      ans = 0;
      for (int i = MAXL - 1; i >= 0; --i) {
        if ((~lup[cur][i]) && ups[cur][i] <= qb)
          qb -= ups[cur][i], cur = lup[cur][i], ans += 1 << i;
      }
      if (ups[cur][0] <= qb) ++ans;
      printf("%d\n", ans);
      lans = ans;
    }
  }
}
