This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define st first
#define nd second
using lint = int64_t;
constexpr int mod = int(1e9) + 7;
constexpr int inf = 0x3f3f3f3f;
constexpr int ninf = 0xcfcfcfcf;
constexpr lint linf = 0x3f3f3f3f3f3f3f3f;
const long double pi = acosl(-1.0);
// Returns -1 if a < b, 0 if a = b and 1 if a > b.
int cmp_double(double a, double b = 0, double eps = 1e-9) {
	return a + eps > b ? b + eps > a ? 0 : 1 : -1;
}
using namespace std;
const int K = 31;
int main() {
	cin.tie(nullptr)->sync_with_stdio(false);
	int q;
	cin>>q;
	vector<array<int, 3>>qr(q);
	vector<vector<int>>g(1);
	int n = 1;
	for(int i=0;i<q;i++){
		string a;
		int x, y;
		cin>>a>>x>>y;
		int t = (a == "Add") ? 0 : 1;
		if(!t) x--;
		else x--, y--;
		if(!t){
			g[x].push_back(n++);
			g.push_back({});
		}
		qr[i] = {t, x, y};
	}
	vector<int>tin(n), tout(n);
	int timer = 0;
	auto dfs = [&](auto& self, int u) -> void{
		tin[u] = ++timer;
		for(int v : g[u]){
			self(self, v);
		}
		tout[u] = timer;
	};
	dfs(dfs, 0);
	vector<int>path(n);
	vector<array<int, 2>>trie(1, {-1, -1});
	vector<set<int>>s(1);
	auto add = [&](int u, int t) ->void{
		int cur = 0;
		for(int a=K;a>=0;a--){
			int b = u>>a&1;
			if(trie[cur][b] == -1){
				trie[cur][b] = (int)trie.size();
				trie.push_back({-1, -1});
				s.push_back({});
			}
			cur = trie[cur][b];
			s[cur].insert(t);
		}
	};
	add(0, tin[0]);
	int id = 1;
	for(auto [t, x, y] : qr){
		if(t == 0){
			path[id] = path[x] ^ y;
			add(path[id], tin[id]);
			id++;
		}
		else{
			int w = path[x];
			int cur = 0, mask = 0;
			for(int a=K;a>=0;a--){
				int b = w>>a&1;
				if(trie[cur][!b] == -1){
					cur = trie[cur][b];
				}
				else{
					int nxt = trie[cur][!b];
					auto it = s[nxt].lower_bound(tin[y]);
					if(it == s[nxt].end() || (*it) > tout[y]){
						cur = trie[cur][b];
					}
					else{
						mask |= (1<<a);
						cur = trie[cur][!b];
					}
				}
			}
			cout<<mask<<"\n";
		}
	}
	return 0;
}
/*
[  ]Leu o problema certo???
[  ]Ver se precisa de long long
[  ]Viu o limite dos fors (é n? é m?)
[  ]Tamanho do vetor, será que é 2e5 em vez de 1e5??
[  ]Testar sample
[  ]Testar casos de  borda
[  ]1LL no 1LL << i
[  ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?)
*/
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |