#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400400;
const int LOG = 19;
const long long INF = 1ll << 60;
int cnt = 1;
long long w[MAXN];
int par[LOG][MAXN];
long long sum[LOG][MAXN];
int dth[MAXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int q;
  int op, r;
  long long x;
  int p, l, d;
  long long s;
  int last = 0;
  w[0] = INF;
  dth[1] = 1;
  cin >> q;
  while (q--) {
    cin >> op >> r >> x;
    r ^= last;
    x ^= last;
    switch (op) {
      case 1:
        p = ++cnt;
        w[p] = x;
        if (w[r] >= w[p])
          par[0][p] = r;
        else {
          for (l = LOG - 1; l >= 0; --l)
            if (w[par[l][r]] < w[p]) r = par[l][r];
          par[0][p] = par[0][r];
        }
        dth[p] = dth[par[0][p]] + 1;
        sum[0][p] = x;
        for (l = 1; l < LOG; ++l) {
          par[l][p] = par[l - 1][par[l - 1][p]];
          sum[l][p] = sum[l - 1][p] + sum[l - 1][par[l - 1][p]];
        }
        break;
      case 2:
        s = d = 0;
        for (l = LOG - 1; l >= 0; --l)
          if ((1 << l) <= dth[r] && s + sum[l][r] <= x) {
            s += sum[l][r];
            d += 1 << l;
            r = par[l][r];
          }
        last = d;
        cout << d << '\n';
        break;
    }
  }
}
