#include <bits/stdc++.h>
using namespace std;
const long long inf = 1ll << 58;
template <class T>
void read(T &x) {
  x = 0;
  long long f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  x *= f;
}
long long n, idx, val[400005], g[400005][24], sum[400005][24];
void gg(long long u, long long fa) {
  if (val[fa] >= val[u]) {
    g[u][0] = fa;
  } else {
    for (int i = 23; i >= 0; --i) {
      if (val[g[fa][i]] < val[u]) fa = g[fa][i];
    }
    g[u][0] = g[fa][0];
  }
  if (g[u][0] == 0)
    sum[u][0] = inf;
  else
    sum[u][0] = val[g[u][0]];
  for (int i = 1; i <= 23; ++i) {
    g[u][i] = g[g[u][i - 1]][i - 1];
    if (g[u][i] == 0)
      sum[u][i] = inf;
    else
      sum[u][i] = sum[g[u][i - 1]][i - 1] + sum[u][i - 1];
  }
}
long long query(long long u, long long c) {
  long long ans = 0;
  if (val[u] <= c) {
    c -= val[u];
    ans = 1;
  } else
    return 0;
  for (long long i = 23; i >= 0; --i) {
    if (sum[u][i] <= c) {
      c -= sum[u][i];
      u = g[u][i];
      ans += (1 << i);
    }
  }
  return ans;
}
int main() {
  read(n);
  long long a, b, c;
  long long last = 0;
  idx = 1;
  val[0] = inf;
  for (int i = 0; i <= 23; ++i) sum[0][i] = sum[1][i] = inf;
  for (long long i = 1; i <= n; ++i) {
    read(a);
    read(b);
    read(c);
    if (a == 1) {
      b = (b ^ last);
      c = (c ^ last);
      val[++idx] = c;
      gg(idx, b);
    }
    if (a == 2) {
      b = (b ^ last);
      c = (c ^ last);
      last = query(b, c);
      printf("%lld\n", last);
    }
  }
}
