#include <bits/stdc++.h>
using namespace std;
int Q, o, cnt, a[(500010)], f[(500010)][22];
long long p, q, r, x, last, ans[(500010)], sum[(500010)];
int main() {
  scanf("%d", &Q);
  ans[0] = -1;
  cnt = 1;
  for (int i = 1; i <= Q; i++) {
    scanf("%d%lld%lld", &o, &p, &q);
    r = p ^ last;
    x = q ^ last;
    if (o == 1) {
      if (a[r] < x) {
        for (int i = 19; i >= 0; i--) {
          if (a[f[r][i]] < x && f[r][i]) r = f[r][i];
        }
        r = f[r][0];
      }
      a[++cnt] = x;
      f[cnt][0] = r;
      ans[cnt] = ans[r] + 1;
      sum[cnt] = sum[r] + x;
      for (int i = 1; i <= 19; i++) f[cnt][i] = f[f[cnt][i - 1]][i - 1];
    } else {
      long long R = r;
      for (int i = 19; i >= 0; i--)
        if (x >= sum[R] - sum[f[r][i]]) r = f[r][i];
      last = ans[R] - ans[r];
      printf("%lld\n", last);
    }
  }
}
