#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 5;
const int mx = 20;
int par[23][maxn];
long long val[maxn], num[maxn], sum[maxn];
int Q;
long long p, q, last;
int z;
long long r, w;
int main() {
  memset(par, -1, sizeof(par));
  int cnt = 1;
  val[1] = 0;
  num[1] = 1;
  par[0][1] = -1;
  sum[1] = 0;
  last = 0;
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%lld%lld", &z, &p, &q);
    r = p ^ last;
    w = q ^ last;
    if (z == 1) {
      cnt++;
      int fa;
      bool ok = false;
      val[cnt] = w;
      if (w <= val[r]) {
        fa = r;
        ok = true;
      } else {
        int t = r;
        for (int k = mx - 1; k >= 0; k--) {
          if (par[k][t] == -1) continue;
          if (val[par[k][t]] < w) {
            t = par[k][t];
          } else
            ok = true;
        }
        if (ok) fa = par[0][t];
      }
      if (!ok) {
        num[cnt] = 1;
        par[0][cnt] = -1;
        sum[cnt] = w;
      } else {
        par[0][cnt] = fa;
        for (int k = 0; k < mx - 1; k++) {
          if (par[k][cnt] == -1)
            par[k + 1][cnt] = -1;
          else
            par[k + 1][cnt] = par[k][par[k][cnt]];
        }
        sum[cnt] = sum[fa] + w;
        num[cnt] = num[fa] + 1;
      }
    } else {
      int t = r;
      long long ans;
      if (sum[r] <= w) {
        ans = num[r];
      } else {
        for (int k = mx - 1; k >= 0; k--) {
          if (par[k][t] == -1) continue;
          if (sum[r] - sum[par[k][t]] <= w) {
            t = par[k][t];
          }
        }
        if (t == r)
          ans = sum[r] <= w ? 1 : 0;
        else {
          ans = num[r] - num[t];
        }
      }
      printf("%lld\n", ans);
      last = ans;
    }
  }
  return 0;
}
