#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <random>
#include <queue>
#include <numeric>
#include <array>
#include <iomanip>
#include <stack>
#include <chrono>
#include <climits>
using namespace std;
using ll = int;
using ld = long double;
using vi = vector<ll>;
using vii = vector<vi>;
using viii = vector<vii>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
using vb = vector<bool>;
using vs = vector<string>;
#define vec vector
#define cmax(x, y) x = max({x, y})
#define cmin(x, y) x = min({x, y})
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const ll N = 2e5 + 5, MOD = 1e9 + 7, INF = (ll)1e18, K = 20;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct Query {
string op;
ll a, b;
};
struct node {
ll one, zero;
set<ll> st;
node() : one(0), zero(0) {}
};
node c[10'000'000];
ll cc = 1;
struct Trie {
ll root;
Trie() : root(cc++) {}
void add(ll x, ll t) {
ll cur = root;
for (ll i = 30; i >= 0; i--) {
if (x >> i & 1) {
if (!c[cur].one) c[cur].one = cc++;
cur = c[cur].one;
}
else {
if (!c[cur].zero) c[cur].zero = cc++;
cur = c[cur].zero;
}
c[cur].st.insert(t);
}
}
ll best(ll x, ll l, ll r) {
ll cur = root;
ll y = 0;
for (ll i = 30; i >= 0; i--) {
if (x >> i & 1) {
if (c[cur].zero && c[c[cur].zero].st.lower_bound(l) != c[c[cur].zero].st.end()
&& *c[c[cur].zero].st.lower_bound(l) <= r) {
cur = c[cur].zero;
}
else {
cur = c[cur].one;
y |= (1 << i);
}
}
else {
if (c[cur].one && c[c[cur].one].st.lower_bound(l) != c[c[cur].one].st.end()
&& *c[c[cur].one].st.lower_bound(l) <= r) {
cur = c[cur].one;
y |= (1 << i);
}
else {
cur = c[cur].zero;
}
}
}
return y ^ x;
}
};
vi g[N];
ll tin[N], tout[N], timer = 1, val[N];
void dfs(ll v) {
tin[v] = timer++;
for (auto& x : g[v]) {
dfs(x);
}
tout[v] = timer - 1;
}
void solve() {
ll q; cin >> q;
vector<Query> qu(q);
ll sz = 1;
for (ll i = 0; i < q; i++) {
cin >> qu[i].op >> qu[i].a >> qu[i].b;
if (qu[i].op == "Add") {
sz++;
g[qu[i].a].push_back(sz);
}
}
dfs(1);
ll n = sz;
sz = 1;
Trie tr; tr.add(val[1], tin[1]);
for (ll i = 0; i < q; i++) {
auto [op, a, b] = qu[i];
if (op == "Add") {
sz++;
val[sz] = val[a] ^ b;
tr.add(val[sz], tin[sz]);
}
else {
cout << tr.best(val[a], tin[b], tout[b]) << '\n';
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long tt = 1;
//cin >> tt;
while (tt--) {
solve();
cout << '\n';
}
return 0;
}
/*
Какие темы повторить:
1) мст
2) 2сат
3) точки артикуляции
4) ксор базис
5) эйлеровый цикл, путь
6) кмп
7) конвекс хулл
8) вафельное дерево
9) суфиксный массив
10) суффиксный автомат
11) ним
*/