#include <bits/stdc++.h>
using namespace std;
const int MXN = 4e5 + 10;
const long long INF = 1e18;
int par[20][MXN], w[MXN];
long long parSum[20][MXN];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int q;
  cin >> q;
  w[0] = 2e9;
  int lst = 0, cur = 1;
  for (int i = 0; i < 20; i++) parSum[i][1] = INF;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      long long p, q;
      cin >> p >> q;
      p ^= lst;
      q ^= lst;
      cur++;
      w[cur] = q;
      if (w[p] >= w[cur]) {
        par[0][cur] = p;
      } else {
        int targetNode = p;
        for (int i = 19; i >= 0; i--) {
          if (w[par[i][targetNode]] < w[cur]) targetNode = par[i][targetNode];
        }
        par[0][cur] = par[0][targetNode];
      }
      parSum[0][cur] = (par[0][cur] == 0 ? INF : w[par[0][cur]]);
      for (int i = 1; i < 20; i++) {
        par[i][cur] = par[i - 1][par[i - 1][cur]];
        parSum[i][cur] =
            (par[i][cur] == 0
                 ? INF
                 : parSum[i - 1][cur] + parSum[i - 1][par[i - 1][cur]]);
      }
    } else {
      long long p, q;
      cin >> p >> q;
      p ^= lst;
      q ^= lst;
      int ans = 0;
      if (w[p] > q)
        ans = 0;
      else {
        q -= w[p];
        ans = 1;
        for (int i = 19; i >= 0; i--) {
          if (parSum[i][p] <= q) {
            ans += (1 << i);
            q -= parSum[i][p];
            p = par[i][p];
          }
        }
      }
      lst = ans;
      cout << ans << '\n';
    }
  }
  return 0;
}
