#include <bits/stdc++.h>
using namespace std;
long long MX, x, y, z, last, pre[400010][21], A[400010], deep[400010],
    sum[400010], cnt = 1;
signed main() {
  scanf("%lld", &MX);
  deep[0] = -1;
  while (MX--) {
    scanf("%lld %lld %lld", &x, &y, &z), y ^= last, z ^= last;
    if (x == 1) {
      if (A[y] < z) {
        for (long long i = 20; i >= 0; i--)
          if (pre[y][i] != 0 && A[pre[y][i]] < z) y = pre[y][i];
        y = pre[y][0];
      }
      cnt++;
      A[cnt] = z, pre[cnt][0] = y, deep[cnt] = deep[y] + 1,
      sum[cnt] = sum[y] + A[cnt];
      for (long long i = 1; i <= 20; i++)
        pre[cnt][i] = pre[pre[cnt][i - 1]][i - 1];
    } else {
      long long now = y;
      for (long long i = 20; i >= 0; i--)
        if (sum[y] - sum[pre[now][i]] <= z) now = pre[now][i];
      last = deep[y] - deep[now];
      printf("%lld\n", last);
    }
  }
  return 0;
}
