#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC optimize(3)
using namespace std;
const long long INF = 1e17;
const long long maxn = 5e5 + 700;
const int mod = 1e9 + 7;
const int base = 180;
template <typename T>
inline void read(T &a) {
  char c = getchar();
  T x = 0, f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  a = f * x;
}
long long n, m, p;
int f[maxn][23];
long long sum[maxn][23];
long long num[maxn];
int cnt = 1;
int main() {
  read(n);
  long long last = 0;
  for (int i = 1; i <= n; i++) {
    long long op, x, y;
    read(op);
    read(x);
    read(y);
    x ^= last;
    y ^= last;
    if (op == 1) {
      num[++cnt] = y;
      if (num[x] >= num[cnt])
        f[cnt][0] = x, sum[cnt][0] = num[x];
      else {
        int p = x;
        for (int i = 20; i >= 0; i--)
          if (f[p][i] && num[f[p][i]] < num[cnt]) p = f[p][i];
        f[cnt][0] = f[p][0];
        sum[cnt][0] = num[f[p][0]];
      }
      for (int i = 1; i <= 20; i++) {
        f[cnt][i] = f[f[cnt][i - 1]][i - 1];
        sum[cnt][i] = sum[cnt][i - 1] + sum[f[cnt][i - 1]][i - 1];
      }
    } else {
      last = 0;
      if (num[x] <= y) {
        long long ans = 1;
        y -= num[x];
        for (int i = 20; i >= 0; i--) {
          if (f[x][i] && sum[x][i] <= y) {
            ans += 1 << i;
            y -= sum[x][i];
            x = f[x][i];
          }
        }
        printf("%lld\n", ans);
        last = ans;
      } else
        printf("0\n");
    }
  }
  return 0;
}
