#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long t = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) t = t * 10 + c - '0', c = getchar();
  return t * f;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    write(-x);
    return;
  }
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
inline void write_p(long long x) {
  write(x);
  putchar(' ');
}
long long Fa[500001][21], n, tv[500001], cnt, opt, x, y;
long long sum[500001][21];
inline void Insert(long long x, long long y, long long v) {
  long long tmp = x;
  if (tv[tmp] < v) {
    for (long long i = 20; i >= 0; --i)
      if (tv[Fa[tmp][i]] < v) tmp = Fa[tmp][i];
    tmp = Fa[tmp][0];
  }
  Fa[y][0] = tmp;
  tv[y] = v;
  sum[y][0] = tv[Fa[y][0]];
  for (long long i = 1; i <= 20; ++i) {
    Fa[y][i] = Fa[Fa[y][i - 1]][i - 1];
    sum[y][i] = sum[y][i - 1] + sum[Fa[y][i - 1]][i - 1];
  }
}
long long ans;
inline void Solve(long long x, long long k) {
  long long tot = 1;
  k -= tv[x];
  if (k < 0) tot = 0;
  for (long long i = 20; i >= 0; --i)
    if (sum[x][i] <= k) tot += 1 << i, k -= sum[x][i], x = Fa[x][i];
  writeln(tot);
  ans = tot;
}
signed main() {
  n = read();
  for (long long i = 0; i <= 20; ++i)
    Fa[1][i] = 0, sum[0][i] = sum[1][i] = 1e17;
  tv[0] = 1e17;
  cnt = 2;
  for (long long i = 1; i <= n; ++i) {
    opt = read();
    x = read() ^ ans;
    y = read() ^ ans;
    if (opt == 1)
      Insert(x, cnt, y), cnt++;
    else
      Solve(x, y);
  }
}
