#include <bits/stdc++.h>
using namespace std;
template <typename T = long long>
void printv(vector<T>& v) {
  for (auto x : v) cout << x << ' ';
  cout << '\n';
}
template <typename T = long long>
void printa(T arr[], long long n) {
  for (long long i = (0); i < (n); i++) cout << arr[i] << ' ';
  cout << '\n';
}
template <typename T = long long>
void printvv(vector<vector<T>>& v) {
  for (auto& x : v) {
    for (auto& y : x) cout << y << ' ';
    cout << '\n';
  }
}
long long powMod(long long a, long long m, long long p = 1000000007) {
  if (m == 0) return 1;
  return (m & 1) ? (a * powMod(a, m - 1, p)) % p
                 : powMod((a * a) % p, m >> 1, p);
}
long long modInv(long long a, long long p = 1000000007) {
  return powMod(a, p - 2, p);
}
long long parent[400001][20];
long long find_par(long long nodes[], long long n, long long wt) {
  if (nodes[n] >= wt) return n;
  for (long long i = 19; i >= 0; i--) {
    if (parent[n][i] != -1) {
      if (nodes[parent[n][i]] < wt) {
        n = parent[n][i];
      }
    }
  }
  return parent[n][0];
}
long long find_sum(long long sum[], long long n, long long wt) {
  if (sum[n] - sum[parent[n][0]] > wt) return 0;
  long long cnt = 0;
  for (long long i = 19; i >= 0; i--) {
    if (parent[n][i] != -1) {
      if (parent[n][i] == 0) continue;
      if (sum[n] - sum[parent[parent[n][i]][0]] <= wt) {
        wt -= (sum[n] - sum[parent[n][i]]);
        n = parent[n][i];
        cnt += ((1LL) << i);
      }
    }
  }
  return cnt + 1;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long q;
  cin >> q;
  long long nodes[400001];
  long long sum[400001];
  nodes[0] = 1000000007;
  sum[0] = 1000000007;
  nodes[1] = 0;
  sum[1] = 1000000007;
  long long cnt = 1;
  memset(parent, -1, sizeof(parent));
  parent[1][0] = 0;
  long long ans = 0;
  for (long long i = 0; i < q; i++) {
    long long k, a, b;
    cin >> k >> a >> b;
    a = a ^ ans;
    b = b ^ ans;
    if (k == 1) {
      nodes[++cnt] = b;
      long long par = find_par(nodes, a, b);
      parent[cnt][0] = par;
      for (long long j = 1; j < 20; j++) {
        parent[cnt][j] = parent[parent[cnt][j - 1]][j - 1];
        if (parent[cnt][j] == -1) break;
      }
      sum[cnt] = nodes[cnt] + sum[par];
    } else {
      cout << (ans = find_sum(sum, a, b)) << endl;
    }
  }
  return 0;
}
