#include <bits/stdc++.h>   using namespace std;   const long long int INF = 9223372036854775807;   const long long int mod = 998244353;   long long int MOD(long long int a, long long int b) {     if (a > b)       return a - b;     else       return b - a;   }   long long int max3(long long int a, long long int b, long long int c) {     return max(c, max(a, b));   }   long long int min3(long long int a, long long int b, long long int c) {     return min(a, min(b, c));   }   long long int power(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = (res * x);       y = y >> 1;       x = (x * x);     }     return res;   }   long long int power1(long long int x, long long int y) {     long long int res = 1;     while (y > 0) {       if (y & 1) res = (res * x) % mod;       y = y >> 1;       x = (x * x) % mod;     }     return res % mod;   }   long long int logg(long long int a) {     long long int x = 0;     while (a > 1) {       x++;       a /= 2;     }     return x;   }   long long int gcd(long long int a, long long int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   long long int abso(long long int x) {     if (x < 0) {       return -x;     }     return x;   }   long long int ceiling(long long int a, long long int b) {     if (a % b == 0) {       return a / b;     } else {       return a / b + 1;     }   }   long long int modinv(long long int x) { return power1(x, mod - 2); }   long long int par[20][400000];   long long int sum[20][400000];   long long int weight[400000];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t;     cin >> t;     long long int cnt = 1;     long long int last = 0;     par[0][1] = 1;     weight[1] = 0;     weight[0] = INF;     for (int i = 0; i < 20; i++) {       for (int j = 0; j < 400000; j++) {         par[i][j] = 0;       }     }     for (int i = 0; i < 20; i++) {       sum[i][1] = INF;     }     for (int i = 0; i < 20; i++) {       for (int j = 2; j < 400000; j++) {         sum[i][j] = 0;       }     }     while (t--) {       int ch;       cin >> ch;       long long int p, q;       cin >> p >> q;       p = p ^ last;       q = q ^ last;       if (ch == 1) {         cnt++;         weight[cnt] = q;         long long int curr = p;         if (weight[p] >= q) {           curr = p;           par[0][cnt] = curr;         } else {           for (int j = 19; j >= 0; j--) {             if (weight[par[j][curr]] < weight[cnt]) {               curr = par[j][curr];             }           }           par[0][cnt] = par[0][curr];         }         if (par[0][cnt] != 0) {           sum[0][cnt] = weight[par[0][cnt]];         } else {           sum[0][cnt] = INF;         }         for (int i = 1; i < 20; i++) {           par[i][cnt] = par[i - 1][par[i - 1][cnt]];         }         for (int i = 1; i < 20; i++) {           if (par[i][cnt] != 0 && sum[i - 1][cnt] != INF) {             sum[i][cnt] = sum[i - 1][cnt] + sum[i - 1][par[i - 1][cnt]];           } else {             sum[i][cnt] = INF;           }         }       } else {         long long int W = weight[p];         if (W > q) {           cout << 0 << endl;           last = 0;         } else {           long long int curr = p;           long long int ans = 1;           for (int j = 19; j >= 0; j--) {             if (sum[j][curr] != INF && sum[j][curr] + W <= q) {               ans += power(2, j);               W += sum[j][curr];               curr = par[j][curr];             }           }           cout << ans << endl;           last = ans;         }       }     }   }