#include <bits/stdc++.h>
using namespace std;
long long w[400005];
long long nxtp[400005][23];
long long sump[400005][23];
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  long long last = 0ll;
  long long cnt = 1ll;
  w[1] = 0;
  w[0] = LLONG_MAX;
  for (int i = 0; i <= 20; i++) {
    sump[1][i] = LLONG_MAX;
  }
  while (t--) {
    long long q, a, b;
    cin >> q >> a >> b;
    a ^= last;
    b ^= last;
    if (q == 1) {
      cnt++;
      w[cnt] = b;
      if (w[a] >= w[cnt])
        nxtp[cnt][0] = a;
      else {
        for (long long j = 20; j >= 0; --j) {
          if (w[nxtp[a][j]] < w[cnt]) a = nxtp[a][j];
        }
        nxtp[cnt][0] = nxtp[a][0];
      }
      sump[cnt][0] = w[nxtp[cnt][0]];
      for (long long j = 1; j <= 20; ++j) {
        nxtp[cnt][j] = nxtp[nxtp[cnt][j - 1]][j - 1];
        if (nxtp[cnt][j] == 0)
          sump[cnt][j] = LLONG_MAX;
        else
          sump[cnt][j] = sump[cnt][j - 1] + sump[nxtp[cnt][j - 1]][j - 1];
      }
    } else {
      if (w[a] > b) {
        cout << "0" << endl;
        last = 0;
        continue;
      }
      b -= w[a];
      long long ans = 1;
      for (long long j = 20; j >= 0; --j) {
        if (b >= sump[a][j]) {
          ans += (1 << j);
          b -= sump[a][j];
          a = nxtp[a][j];
        }
      }
      cout << ans << endl;
      last = ans;
    }
  }
  return 0;
}
