#include <bits/stdc++.h>
using namespace std;
const int N = 400008;
const long long M = 1e16;
long long tot, t, last, a[N][20], b[N][20], w[N];
int main(void) {
  std::ios::sync_with_stdio(false);
  long long i, k, op, p1, p2;
  last = 0;
  tot = 1;
  w[0] = M;
  w[1] = 0;
  for (i = 0; i <= 19; i++) b[1][i] = M;
  cin >> t;
  while (t--) {
    cin >> op >> p1 >> p2;
    p1 ^= last;
    p2 ^= last;
    if (op == 1) {
      w[++tot] = p2;
      k = p1;
      while (w[k] < w[tot]) {
        for (i = 0; w[a[k][i]] < w[tot]; i++)
          ;
        k = a[k][i ? (i - 1) : 0];
      }
      a[tot][0] = k;
      b[tot][0] = w[k];
      for (i = 1; i <= 19; i++) {
        a[tot][i] = a[a[tot][i - 1]][i - 1];
        b[tot][i] = b[tot][i - 1] + b[a[tot][i - 1]][i - 1];
      }
    } else {
      if (w[p1] > p2) {
        cout << (last = 0) << endl;
        continue;
      }
      last = 1;
      p2 -= w[p1];
      k = p1;
      while (k != 0) {
        for (i = 0; i <= 19 && a[k][i] && b[k][i] <= p2; i++)
          ;
        if (i == 0)
          break;
        else
          i--;
        last += (1 << i);
        p2 -= b[k][i];
        k = a[k][i];
      }
      cout << last << endl;
    }
  }
  return 0;
}
