#include <bits/stdc++.h>
using namespace std;
const int M = 4e5 + 10;
int cnt = 1;
long long a[M];
struct note {
  int node;
  long long sum;
} f[M][20];
int main() {
  int q;
  memset(f, 0, sizeof(f));
  scanf("%d", &q);
  long long last = 0;
  while (q--) {
    int opt;
    long long u, x;
    scanf("%d", &opt);
    if (opt == 1) {
      scanf("%lld%lld", &u, &x);
      u ^= last, x ^= last;
      a[++cnt] = x;
      for (int k = 19; k >= 0; k--)
        if (f[u][k].node && a[f[u][k].node] < a[cnt]) u = f[u][k].node;
      if (a[u] >= a[cnt]) {
        f[cnt][0].node = u;
        f[cnt][0].sum = a[u];
      } else {
        f[cnt][0].node = f[u][0].node;
        f[cnt][0].sum = f[u][0].sum;
      }
      for (int i = 1; i < 20; i++) {
        f[cnt][i].node = f[f[cnt][i - 1].node][i - 1].node;
        f[cnt][i].sum = f[cnt][i - 1].sum + f[f[cnt][i - 1].node][i - 1].sum;
      }
    } else {
      scanf("%lld%lld", &u, &x);
      u ^= last, x ^= last;
      long long res = 0;
      if (x >= a[u]) res++;
      x -= a[u];
      for (int i = 19; i >= 0; i--) {
        if (f[u][i].node && f[u][i].sum <= x) {
          res += 1 << i;
          x -= f[u][i].sum;
          u = f[u][i].node;
        }
      }
      printf("%lld\n", res);
      last = res;
    }
  }
  return 0;
}
