#include <bits/stdc++.h>
using namespace std;
template <class T>
void rd(T& ret) {
  ret = 0;
  bool ok = 0, u = 0;
  for (;;) {
    int c = getchar();
    if (c >= '0' && c <= '9')
      ret = (ret << 3) + (ret << 1) + c - '0', ok = 1;
    else if (c == '-')
      u = 1;
    else if (ok) {
      if (u) ret *= -1;
      return;
    }
  }
}
long long pow_mod(long long p, long long n, long long mod) {
  long long ret = 1;
  for (; n; n >>= 1) {
    if (n & 1) ret = ret * p % mod;
    p = p * p % mod;
  }
  return ret;
}
template <class T>
bool chmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool chmax(T& a, const T& b) {
  return b > a ? a = b, 1 : 0;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const int N = (int)400009;
const int B = 20;
int w[N], dep[N];
int f[N][20];
long long sum[N][20];
void gao(int first, int p) {
  if (p == -1)
    dep[first] = 0;
  else
    dep[first] = dep[p] + 1;
  f[first][0] = p;
  sum[first][0] = w[first];
  for (int i = 1; f[first][i - 1] != -1; ++i) {
    f[first][i] = f[f[first][i - 1]][i - 1];
    sum[first][i] = sum[first][i - 1] + sum[f[first][i - 1]][i - 1];
  }
}
int get_node(int first, int len) {
  for (int i = (0); i < (B); i++) {
    if (first == -1) break;
    if (len & 1) first = f[first][i];
    len >>= 1;
    if (len == 0) break;
  }
  return first;
}
int find(int first, int we) {
  int ans = -1, l = 0, r = dep[first] + 1, mid, t;
  while (l <= r) {
    mid = (l + r) >> 1;
    t = get_node(first, mid);
    if (w[t] >= we) {
      ans = t;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  return ans;
}
long long query_sum(int first, int d) {
  long long ans = 0;
  for (int i = (0); i < (B); i++) {
    if (first == -1) break;
    if (d & 1) {
      ans += sum[first][i];
      first = f[first][i];
    }
    d >>= 1;
    if (d == 0) break;
  }
  return ans;
}
int main() {
  int _;
  scanf("%d", &_);
  memset(f, -1, sizeof f);
  int last = 0;
  int cnt = 1;
  w[0] = 0;
  dep[0] = 0;
  f[0][0] = -1;
  sum[0][0] = 0;
  int op, a;
  long long b;
  while (_--) {
    scanf("%d%d%lld", &op, &a, &b);
    a = a ^ last;
    b = b ^ last;
    if (op == 1) {
      --a;
      w[cnt] = b;
      int p = find(a, b);
      gao(cnt, p);
      ++cnt;
    } else {
      --a;
      int ans = 0, l = 0, r = dep[a] + 1, mid;
      while (l <= r) {
        mid = (l + r) >> 1;
        if (query_sum(a, mid) <= b) {
          ans = mid;
          l = mid + 1;
        } else {
          r = mid - 1;
        }
      }
      last = ans;
      printf("%d\n", ans);
    }
  }
  return 0;
}
