#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3fll;
long long fa[500010][23], sum[500010][23], w[500010], n, cnt;
inline long long read() {
  long long s = 0, w = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') w = -1;
  for (; isdigit(c); c = getchar()) s = (s << 1) + (s << 3) + (c ^ 48);
  return s * w;
}
void add(int u, int x) {
  w[++cnt] = x;
  if (w[u] >= w[cnt])
    fa[cnt][0] = u;
  else {
    for (int i = 20; i >= 0; --i)
      if (w[fa[u][i]] < w[cnt]) u = fa[u][i];
    fa[cnt][0] = fa[u][0];
  }
  sum[cnt][0] = w[fa[cnt][0]];
  for (int i = 1; i <= 20; ++i) {
    fa[cnt][i] = fa[fa[cnt][i - 1]][i - 1];
    if (fa[cnt][i])
      sum[cnt][i] = sum[cnt][i - 1] + sum[fa[cnt][i - 1]][i - 1];
    else
      sum[cnt][i] = inf;
  }
}
long long query(int u, long long x) {
  if (w[u] > x) return 0;
  long long ans = 1;
  x -= w[u];
  for (int i = 20; i >= 0; --i)
    if (sum[u][i] <= x) x -= sum[u][i], ans += (1 << i), u = fa[u][i];
  return ans;
}
int main() {
  n = read();
  memset(sum[1], inf, sizeof(sum[1]));
  long long last = 0;
  cnt = 1;
  w[0] = inf;
  w[1] = 0;
  while (n--) {
    long long opt = read(), x = read(), y = read();
    x ^= last, y ^= last;
    if (opt == 1)
      add(x, y);
    else
      printf("%lld\n", last = query(x, y));
  }
  return 0;
}
