#include <bits/stdc++.h>
namespace patch {
template <typename T>
std::string to_string(const T& n) {
  std::ostringstream stm;
  stm << n;
  return stm.str();
}
}  // namespace patch
using namespace std;
long long sp[400005][22], mx[400005][22], sum[400005][22], lev[400005];
long long NewPar(long long Node, long long W) {
  for (int i = 21; i >= 0; i--) {
    if (sp[Node][i] && mx[Node][i] < W) {
      Node = sp[Node][i];
    }
  }
  if (mx[Node][0] >= W) {
    return Node;
  }
  return sp[Node][0];
}
void add(long long P, long long U, long long W) {
  P = NewPar(P, W);
  lev[U] = lev[P] + 1;
  sp[U][0] = P;
  mx[U][0] = W;
  sum[U][0] = W;
  for (int i = 1; i < 22; i++) {
    long long V = sp[U][i - 1];
    sp[U][i] = sp[V][i - 1];
    mx[U][i] = max(mx[U][i - 1], mx[V][i - 1]);
    sum[U][i] = sum[U][i - 1] + sum[V][i - 1];
  }
}
long long solve(long long U, long long W) {
  long long ans = 0;
  for (int i = 21; i >= 0; i--) {
    if (lev[U] >= (1 << i) && sum[U][i] <= W) {
      W -= sum[U][i];
      ans += (1 << i);
      U = sp[U][i];
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long Q, last = 0;
  cin >> Q;
  lev[1] = 1;
  long long cnt = 2;
  while (Q--) {
    long long T, R, B;
    cin >> T >> R >> B;
    R ^= last;
    B ^= last;
    if (T == 1) {
      add(R, cnt, B);
      cnt++;
    } else {
      last = solve(R, B);
      cout << last << '\n';
    }
  }
  return 0;
}
