#include <bits/stdc++.h>
struct E {
  int nx, to;
} edge[400005];
int tot = 1;
int fa[400005][20], dep[400005];
long long val[400005], cost[400005];
void Addedge(int a, long long d) {
  fa[++tot][0] = a;
  val[tot] = d;
  if (val[a] >= d) {
    fa[tot][0] = a;
  } else {
    int from = a;
    for (int i = 19; i >= 0; i--) {
      if (!fa[from][i]) continue;
      if (val[fa[from][i]] < d) from = fa[from][i];
    }
    fa[tot][0] = fa[from][0];
  }
  dep[tot] = dep[fa[tot][0]] + 1;
  cost[tot] = cost[fa[tot][0]] + d;
  for (int i = 1; i < 20; i++) fa[tot][i] = fa[fa[tot][i - 1]][i - 1];
}
int Query(int p, long long q) {
  long long len = q;
  int from = p, ans = 0;
  for (int i = 19; i >= 0; i--) {
    if (!fa[from][i]) continue;
    if (cost[from] - cost[fa[from][i]] <= len) {
      ans += dep[from] - dep[fa[from][i]];
      len -= cost[from] - cost[fa[from][i]];
      from = fa[from][i];
    }
  }
  if (val[from] <= len) ans++;
  return ans;
}
int main() {
  int Q, last = 0;
  scanf("%d", &Q);
  dep[1] = 1;
  val[0] = 4611686018427387904;
  while (Q--) {
    int a;
    long long p, q;
    scanf("%d%lld%lld", &a, &p, &q);
    p = last ^ p, q = last ^ q;
    if (a == 1) {
      Addedge(p, q);
    } else {
      last = Query(p, q);
      printf("%d\n", last);
    }
  }
}
