#include <bits/stdc++.h>
using namespace std;
const int MAX = 400000 + 5;
long long w[MAX];
long long mxW[MAX][19];
int par[MAX][19];
int par2[MAX][19];
long long cumW[MAX][19];
int level[MAX], level2[MAX];
int main() {
  long long last = 0;
  int cnt = 1;
  int q2;
  scanf("%d", &q2);
  for (int i = 0; i <= 18; i++) mxW[0][i] = -1;
  w[0] = -1;
  level[1] = level2[1] = 1;
  while (q2--) {
    long long t, p, q;
    scanf("%I64d %I64d %I64d", &t, &p, &q);
    if (t == 1) {
      long long R = p ^ last;
      long long W = q ^ last;
      ++cnt;
      par[cnt][0] = R;
      level[cnt] = level[R] + 1;
      w[cnt] = W;
      mxW[R][0] = w[R];
      for (int i = 1; i <= 18; i++) {
        par[cnt][i] = par[par[cnt][i - 1]][i - 1];
        mxW[R][i] = max(mxW[R][i - 1], mxW[par[R][i - 1]][i - 1]);
      }
      int to = R;
      for (int i = 18; i >= 0; i--) {
        if (level[to] < (1 << i)) continue;
        if (mxW[to][i] < W) to = par[to][i];
      }
      if (to == 0) {
        level2[cnt] = 1;
        for (int i = 0; i <= 18; i++) cumW[cnt][i] = W;
        continue;
      }
      if (w[to] < W) to = par[to][0];
      assert(to != 0);
      level2[cnt] = level2[to] + 1;
      par2[cnt][0] = to;
      cumW[cnt][0] = W;
      for (int i = 1; i <= 18; i++) {
        par2[cnt][i] = par2[par2[cnt][i - 1]][i - 1];
        cumW[cnt][i] = cumW[cnt][i - 1] + cumW[par2[cnt][i - 1]][i - 1];
      }
    } else {
      long long R = p ^ last;
      long long X = q ^ last;
      int ans = 0, cur = R;
      for (int i = 18; i >= 0; i--) {
        if (level2[cur] < (1 << i)) continue;
        if (cumW[cur][i] <= X) {
          X -= cumW[cur][i];
          cur = par2[cur][i];
          ans |= (1 << i);
        }
      }
      last = ans;
      printf("%I64d\n", last);
    }
  }
  return 0;
}
