#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int sum = 0, p = 1;
  char ch = getchar();
  while (!(('0' <= ch && ch <= '9') || ch == '-')) ch = getchar();
  if (ch == '-') p = -1, ch = getchar();
  while ('0' <= ch && ch <= '9') sum = sum * 10 + ch - 48, ch = getchar();
  return sum * p;
}
const int maxn = 4e5 + 20;
const int maxp = 19;
const long long inf = 1ll << 63 - 1;
int n;
int p[maxn][20];
long long pw[maxn][20];
int w[maxn];
long long pww[maxn][20];
int pp[maxn][20], cnt;
void init() { n = read(); }
void doing() {
  int ans = 0;
  cnt = 1;
  for (int i = (1), _end_ = (n); i <= _end_; i++) {
    int opt;
    long long x, y;
    scanf("%d%lld%lld", &opt, &x, &y);
    x ^= ans;
    y ^= ans;
    if (opt == 1) {
      ++cnt;
      p[cnt][0] = x;
      w[cnt] = y;
      pw[cnt][0] = w[x];
      for (int i = (1), _end_ = (maxp); i <= _end_; i++)
        p[cnt][i] = p[p[cnt][i - 1]][i - 1],
        pw[cnt][i] = max(pw[cnt][i - 1], pw[p[cnt][i - 1]][i - 1]);
      int u = cnt;
      for (int i = (maxp), _end_ = (0); i >= _end_; i--)
        if (pw[u][i] < w[cnt]) u = p[u][i];
      u = p[u][0];
      pp[cnt][0] = u;
      pww[cnt][0] = w[u];
      for (int i = (1), _end_ = (maxp); i <= _end_; i++)
        pp[cnt][i] = pp[pp[cnt][i - 1]][i - 1];
      for (int i = (1), _end_ = (maxp); i <= _end_; i++)
        pww[cnt][i] = pww[cnt][i - 1] + pww[pp[cnt][i - 1]][i - 1];
    } else {
      if (y < w[x]) {
        ans = 0;
        puts("0");
        continue;
      }
      ans = 1;
      y -= w[x];
      int u = x;
      for (int i = (maxp), _end_ = (0); i >= _end_; i--) {
        if (pp[u][i] && pww[u][i] <= y) {
          y -= pww[u][i];
          ans += 1 << i;
          u = pp[u][i];
        }
      }
      printf("%d\n", ans);
    }
  }
}
int main() {
  init();
  doing();
  return 0;
}
