#include <bits/stdc++.h>
using namespace std;
const int N = 400010;
int P[20][N];
long long W[N];
long long S[20][N];
bool check(int len, int R, long long X) {
  if (len == 0) return 1;
  if (len == 1) return W[R] <= X;
  long long sum = 0;
  len--;
  for (int i = 0; i < 20; i++) {
    if ((len & (1 << i)) == 0) continue;
    if (P[i][R] == -1) return 0;
    sum += S[i][R];
    R = P[i][R];
  }
  sum += W[R];
  return sum <= X;
}
int main() {
  memset(P, -1, sizeof P);
  memset(W, 0, sizeof 0);
  memset(S, 0, sizeof S);
  int cnt = 1;
  int q;
  scanf("%d", &q);
  long long lastAnswer = 0;
  while (q--) {
    long long pp, qq;
    int type;
    scanf("%d", &type);
    long long A, B;
    scanf("%I64d", &pp);
    scanf("%I64d", &qq);
    A = pp ^ lastAnswer;
    B = qq ^ lastAnswer;
    if (type == 1) {
      int X = ++cnt;
      for (int i = 19; i >= 0; --i) {
        if (P[i][A] == -1) continue;
        if (W[P[i][A]] < B) A = P[i][A];
      }
      if (W[A] >= B)
        P[0][X] = A;
      else
        P[0][X] = P[0][A];
      W[X] = B;
      S[0][X] = W[X];
      for (int i = 1; i < 20; i++) {
        int par = P[i - 1][X];
        if (par == -1) continue;
        P[i][X] = P[i - 1][par];
        S[i][X] = S[i - 1][X] + S[i - 1][par];
      }
    } else {
      long long l = 0, r = cnt, mid, res = 0;
      while (l <= r) {
        mid = (l + r) >> 1;
        if (check(mid, A, B))
          res = mid, l = mid + 1;
        else
          r = mid - 1;
      }
      printf("%I64d\n", res);
      lastAnswer = res;
    }
  }
  return 0;
}
