#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 2e5;
int t;
vector <int> adj[MAXN+5];
int tin[MAXN+5], tout[MAXN+5], dist[MAXN+5];
int X[MAXN+5], A[MAXN+5], B[MAXN+5];
struct Trie {
int lvl;
Trie *ch[2] = {NULL};
set <int> st;
void ins(int z, int idx) {
if (!lvl) return;
if (ch[(z>>lvl-1)&1] == NULL) {
ch[(z>>lvl-1)&1] = new Trie();
ch[(z>>lvl-1)&1]->lvl = lvl-1;
}
ch[(z>>lvl-1)&1]->st.insert(idx);
ch[(z>>lvl-1)&1]->ins(z, idx);
}
int query(int z, int x, int y) {
if (!lvl) return 0LL;
if (ch[!((z>>lvl-1)&1)] != NULL) {
auto it = ch[!((z>>lvl-1)&1)]->st.lower_bound(x);
if (it != ch[!((z>>lvl-1)&1)]->st.end() && (*it) <= y) return (1LL<<lvl-1)+ch[!((z>>lvl-1)&1)]->query(z, x, y);
}
if (ch[(z>>lvl-1)&1] != NULL) return ch[(z>>lvl-1)&1]->query(z, x, y);
return 0LL;
}
};
void dfs(int idx) {
tin[idx] = ++t;
for (auto i : adj[idx]) {
dfs(i);
}
tout[idx] = t;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int tc = 1;
// cin >> tc;
while (tc--) {
int Q; cin >> Q;
int N = 1;
for (int i = 1; i <= Q; i++) {
string S; cin >> S;
if (S == "Add") {
int P, val; cin >> P >> val;
X[i] = ++N;
adj[P].push_back(N);
dist[N] = (dist[P]^val);
}
else {
cin >> A[i] >> B[i];
}
}
dfs(1);
Trie trie;
trie.lvl = 30;
trie.ins(0, tin[1]);
for (int i = 1; i <= Q; i++) {
if (X[i]) {
trie.ins(dist[X[i]], tin[X[i]]);
}
else {
cout << trie.query(dist[A[i]], tin[B[i]], tout[B[i]]) << "\n";
}
}
}
}
/*
*/