#include <bits/stdc++.h>
using namespace std;
long long G[400005][19], p, q;
int a[400005], F[400005][19], n, ans;
int Find(int u) {
  if (a[u] >= q || u == 0) return u;
  return Find(F[u][0]);
}
int main() {
  memset(G, -1, sizeof(G));
  int Q;
  scanf("%d", &Q);
  n = 1;
  a[0] = G[1][0] = 0;
  while (Q--) {
    int opt;
    scanf("%d%lld%lld", &opt, &p, &q);
    p ^= ans;
    q ^= ans;
    if (opt == 1) {
      ++n;
      a[n] = q;
      F[n][0] = Find(p);
      G[n][0] = q;
      for (int k = 1; k <= 18; k++) F[n][k] = F[F[n][k - 1]][k - 1];
      for (int k = 1; k <= 18; k++)
        if (G[n][k - 1] != -1 && G[F[n][k - 1]][k - 1] != -1)
          G[n][k] = G[n][k - 1] + G[F[n][k - 1]][k - 1];
    } else {
      ans = 0;
      for (int k = 18; k >= 0; k--)
        if (G[p][k] != -1 && G[p][k] <= q)
          q -= G[p][k], p = F[p][k], ans += 1 << k;
      printf("%d\n", ans);
    }
  }
}
