#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 7; typedef long long ll; int f[maxn][20]; ll dp[maxn][20], val[maxn]; int main() { int t, op; scanf("%d", &t); int cnt = 1; f[1][0] = 0; val[1] = 0; val[0] = 1e18; ll p, q, r, x, last = 0; while (t--) { scanf("%d%lld%lld", &op, &p, &q); if(op == 1) { r = p ^ last; x = q ^ last; cnt++; val[cnt] = x; if(val[r] >= val[cnt]) f[cnt][0] = r; else { for (int i = 19; i >= 0; i--) { if(val[f[r][i]] < x) r = f[r][i]; } f[cnt][0] = f[r][0]; } dp[cnt][0] = val[f[cnt][0]]; for (int i = 1; i <= 19; i++) { f[cnt][i] = f[f[cnt][i - 1]][i - 1]; if(dp[cnt][i - 1] < 1e18 && f[cnt][i]) dp[cnt][i] = dp[cnt][i - 1] + dp[f[cnt][i - 1]][i - 1]; else break; } } else { r = p ^ last; x = q ^ last; // printf("%lld %lld\n", r, x); last = 0; if(val[r] <= x) last++, x -= val[r]; else { printf("%d\n", last); continue; } // printf("val[r] = %d x = %lld, last = %d\n", val[r], x, last); // printf("%lld\n", dp[3][0]); for (int i = 19; i >= 0; i--) { if(f[r][i] && dp[r][i] <= x) { // printf("i = %d , f = %d, dp = %lld\n", i, f[r][i], dp[r][i]); x -= dp[r][i]; r = f[r][i]; last += (1<<i); } } printf("%d\n", last); } } }