#include <bits/stdc++.h>
const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
const long long inf = 1ll << 60;
const int mod = 1e9 + 7;
const int N = 400005;
const int Len = 10000000;
int n = 1, q, fa[N][19], lev[N];
long long val[N], sum[N][19], ans = 0;
using namespace std;
void upd(int& x, int y) {
  x += y;
  if (x >= mod) x -= mod;
}
void update() {
  int i;
  sum[n][0] = val[n];
  for (i = 1; i <= 18; i++) {
    fa[n][i] = fa[fa[n][i - 1]][i - 1];
    sum[n][i] = sum[n][i - 1] + sum[fa[n][i - 1]][i - 1];
  }
}
void insert(int f, int v) {
  n++, val[n] = v;
  if (val[f] >= val[n]) {
    fa[n][0] = f, update();
    return;
  }
  int i;
  for (i = 18; i >= 0; i--)
    if (val[fa[f][i]] < val[n]) f = fa[f][i];
  f = fa[f][0];
  if (!f) {
    for (i = 0; i <= 18; i++) sum[n][i] = v;
    return;
  }
  fa[n][0] = f, update();
}
long long query(int st, long long lim) {
  int rtn = 0, i, l = st;
  for (i = 18; i >= 0; i--)
    if (sum[st][i] <= lim) lim -= sum[st][i], rtn += (1 << i), st = fa[st][i];
  if (!st) return lev[l];
  return rtn;
}
int main() {
  scanf("%d", &q);
  val[0] = inf;
  lev[1] = 1;
  while (q--) {
    int typ;
    long long x, y;
    scanf("%d %lld %lld", &typ, &x, &y);
    x ^= ans, y ^= ans;
    if (typ == 1)
      insert((int)x, (int)y), lev[n] = lev[fa[n][0]] + 1;
    else
      printf("%lld\n", ans = query((int)x, y));
  }
  return 0;
}
