#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const int N = 4e5 + 10;
const int M = 1e6 + 10;
const long long mod = 1e9 + 7;
const double PI = acos(-1);
long long w[N];
int fa[N][21];
long long wi[N][21];
long long mx[N][21];
int Find(int x, int y) {
  for (int i = 20; i >= 0; --i)
    if (mx[x][i] < y) x = fa[x][i];
  return x;
}
int dd[21];
int main() {
  dd[0] = 1;
  for (int i = 1; i <= 20; ++i) dd[i] = dd[i - 1] * 2;
  int cnt = 1, last = 0;
  w[0] = 1e16;
  for (int i = 0; i <= 20; ++i) fa[0][i] = 0, wi[0][i] = 1e16, mx[0][i] = 1e16;
  w[1] = 0, fa[1][0] = 0, wi[1][0] = 0;
  for (int i = 1; i <= 20; ++i) fa[1][i] = 0, wi[1][i] = 1e16, mx[1][i] = 1e16;
  int q, to, op;
  long long x, y;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%I64d%I64d", &op, &x, &y);
    x ^= last, y ^= last;
    if (op == 1) {
      w[++cnt] = y;
      fa[cnt][0] = Find(x, y);
      mx[cnt][0] = wi[cnt][0] = w[cnt];
      for (int i = 1; i <= 20; ++i) {
        to = fa[cnt][i - 1];
        fa[cnt][i] = fa[to][i - 1];
        mx[cnt][i] = max(mx[cnt][i - 1], mx[to][i - 1]);
        wi[cnt][i] = wi[cnt][i - 1] + wi[to][i - 1];
      }
    } else {
      last = 0;
      for (int i = 20; i >= 0; --i) {
        if (wi[x][i] <= y) {
          last += dd[i];
          y -= wi[x][i];
          x = fa[x][i];
        }
      }
      printf("%d\n", last);
    }
  }
  return 0;
}
