#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
const int N = 4e5 + 10;
int f[20][N], g[20][N];
long long sum[20][N];
long long w[N];
int main() {
  int m, n = 1;
  w[0] = 0;
  for (int k = 0; k < 20; ++k) {
    f[k][0] = -1;
    g[k][0] = -1;
  }
  scanf("%d", &m);
  long long ret = 0;
  while (m--) {
    long long t, p, q;
    scanf("%lld%lld%lld", &t, &p, &q);
    p ^= ret;
    q ^= ret;
    if (t == 1) {
      assert(p >= 1 && p <= n);
      assert(q >= 0 && q <= 1000000000LL);
      --p;
      f[0][n] = p;
      for (int k = 1; k < 20; ++k) {
        f[k][n] = f[k - 1][n] < 0 ? -1 : f[k - 1][f[k - 1][n]];
      }
      w[n] = q;
      if (w[p] < w[n]) {
        for (int k = 19; k >= 0; --k) {
          if (g[k][p] >= 0 && w[g[k][p]] < w[n]) {
            p = g[k][p];
          }
        }
        p = g[0][p];
      }
      if (w[p] >= w[n]) {
        g[0][n] = p;
        sum[0][n] = w[p];
      } else {
        g[0][n] = -1;
        sum[0][n] = 0;
      }
      for (int k = 1; k < 20; ++k) {
        if (g[k - 1][n] < 0) {
          g[k][n] = -1;
          sum[k][n] = sum[k - 1][n];
        } else {
          g[k][n] = g[k - 1][g[k - 1][n]];
          sum[k][n] = sum[k - 1][n] + sum[k - 1][g[k - 1][n]];
        }
      }
      ++n;
    } else {
      assert(p >= 1 && p <= n);
      assert(q >= 0 && q <= 1000000000LL * 1000000LL);
      --p;
      if (w[p] > q) {
        puts("0");
        ret = 0;
        continue;
      }
      long long cur = w[p];
      ret = 1;
      for (int k = 19; k >= 0; --k) {
        if (g[k][p] >= 0 && sum[k][p] + cur <= q) {
          cur += sum[k][p];
          p = g[k][p];
          ret += 1 << k;
        }
      }
      printf("%lld\n", ret);
    }
  }
  return 0;
}
