#include <bits/stdc++.h>
using namespace std;
inline bool equal(double _x, double _y) {
  return _x > _y - 1e-9 && _x < _y + 1e-9;
}
int cur = 1;
long long w[400005], p[25][400005], s[25][400005], len[25][400005];
void add(int pa, long long val) {
  w[cur] = val;
  int now = pa;
  for (int i = 20; i >= 0; i--) {
    if (w[p[i][now]] < val) now = p[i][now];
  }
  now = p[0][now];
  if (w[pa] >= val) now = pa;
  if (w[now] >= val) {
    len[0][cur] = 1;
    p[0][cur] = now;
    s[0][cur] = w[now];
    for (int i = 1; i <= 20; i++) {
      p[i][cur] = p[i - 1][p[i - 1][cur]];
      s[i][cur] = s[i - 1][cur] + s[i - 1][p[i - 1][cur]];
      len[i][cur] = len[i - 1][cur] + len[i - 1][p[i - 1][cur]];
    }
  } else {
    for (int i = 0; i <= 20; i++) p[i][cur] = cur;
  }
  cur++;
}
long long query(long long x, long long val) {
  if (w[p[0][x]] > val || p[0][x] == x) return 0LL;
  int st = 20;
  while (s[st][x] > val) st--;
  return len[st][x] + query(p[st][x], val - s[st][x]);
}
int main() {
  int Q, op;
  long long pp, q, last = 0LL;
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%lld%lld", &op, &pp, &q);
    long long R = (pp ^ last) - 1;
    long long W = q ^ last;
    if (op == 1) {
      add((int)R, W);
    } else {
      last = query(R, W - w[R]) + (w[R] <= W ? 1 : 0);
      printf("%lld\n", last);
    }
  }
}
