// Author: Muhtasim Hossain Musanna (Musanna47 / mhmusanna)
#include "bits/stdc++.h"
using namespace std;
#define nl "\n"
#define REPF(_i, _a, _b) for(int _i = _a; _i <= _b; _i++)
#define REPB(_i, _a, _b) for(int _i = _a; _i >= _b; _i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#define sza(_x) ((int)_x.size())
#define all(_x) _x.begin(), _x.end()
#define sort_des(_x) sort(all(_x), greater())
#define min_heap(_T, _pq, _cmp) auto _cmp = greater(); priority_queue<_T, vector<_T>, decltype(_cmp)> _pq(_cmp)
template <typename T1, typename T2>
using P = pair<T1, T2>;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = V<V<T>>;
template <typename T>
using VVV = V<V<V<T>>>;
template <typename T>
using VVVV = V<V<V<V<T>>>>;
using S = string;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pii = P<int, int>;
using pll = P<ll, ll>;
using vi = V<int>;
using vvi = VV<int>;
using vll = V<ll>;
using vvll = VV<ll>;
using vpii = V<pii>;
using vpll = V<pll>;
template <typename T>
void pout(T a, string sep = " ", string fin = "\n") {
cout << a.first << sep << a.second << fin;
}
template <typename T>
void print(T& a, ll l, ll r, string sep = " ", string fin = "\n") {
for (ll i = l; i <= r; i++)
cout << a[i] << sep;
cout << fin;
}
template <typename T>
void printPairs(T& a, ll l, ll r, string fin = "\n") {
for (ll i = l; i <= r; i++)
pout(a[i]);
cout << fin;
}
template <typename T>
void printAll(T& a, string sep = " ", string fin = "\n") {
for (auto& ele : a)
cout << ele << sep;
cout << fin;
}
template <typename T>
void printPairsAll(T& a, string fin = "\n") {
for (auto& ele : a)
pout(ele);
cout << fin;
}
template <typename... Args>
void read(Args&... args) {
((cin >> args), ...);
}
template <typename... Args>
void out(Args... args) {
((cout << args << " "), ...);
}
template <typename... Args>
void outln(Args... args) {
((cout << args << " "), ...);
cout << nl;
}
template <typename T>
void vin(T& a, ll l, ll r) {
for (ll i = l; i <= r; i++)
cin >> a[i];
}
template <typename T>
void makeUnique(T& a) {
a.erase(unique(all(a)), a.end());
}
using bll = __int128;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.141592653589793;
const double EPS = 1e-12;
mt19937_64 rnd(239);
//mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
void prec() {
}
const int N = 2e5 + 5, D = 31;
tuple<int, int, int> queries[N];
int val[N], prefVal[N], st[N], et[N], nodes = 1, ct = 0, tot = 0;
int pref[N << 1], trie[N * D][2];
vi G[N];
set<int> stimes[N * D];
inline namespace Trie {
void add(int x, int node) {
int u = 0;
for (int d = D - 1; d >= 0; d--) {
bool v = x & (1 << d);
if (!trie[u][v])
trie[u][v] = ++tot;
u = trie[u][v];
stimes[u].emplace(st[node]);
}
}
int getMax(int x, int node) {
int u = 0, ret = 0;
for (int d = D - 1; d >= 0; d--) {
bool v = x & (1 << d);
if (trie[u][!v]) {
auto it = stimes[trie[u][!v]].upper_bound(st[node]);
if (it != stimes[trie[u][!v]].end() && *it < et[node]) {
u = trie[u][!v];
ret |= (1 << d);
} else {
u = trie[u][v];
}
} else {
u = trie[u][v];
}
}
return ret;
}
}
void dfs(int u = 1) {
st[u] = ++ct;
for (auto& v : G[u]) {
dfs(v);
}
et[u] = ++ct;
}
int getDist(int x, int y) {
return pref[st[x]] ^ pref[st[y]];
}
void solve() {
int q;
read(q);
REPF(i, 1, q) {
auto& [t,x,y] = queries[i];
S s;
read(s, x, y);
if (s == "Query") {
t = 1;
} else {
G[x].emplace_back(++nodes);
val[nodes] = y;
prefVal[nodes] = prefVal[x] ^ y;
y = nodes;
}
}
dfs();
REPF(i, 1, nodes) {
pref[st[i]] = val[i];
pref[et[i]] = val[i];
}
REPF(i, 1, nodes<<1) {
pref[i] ^= pref[i - 1];
}
REPF(i, 1, q) {
auto& [t,x,y] = queries[i];
if (t) {
int ans = getDist(x, y);
ans = max(ans, getMax(ans ^ prefVal[y], y));
cout << ans << nl;
} else {
add(prefVal[y], y);
}
}
}
void OJ() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
signed main() {
// OJ();
cin.tie(0)->sync_with_stdio(0);
// cout << fixed << setprecision(10);
// prec();
int tc = 1;
// cin >> tc;
for (int i = 1; i <= tc; i++) {
// cout << "Case " << i << ": ";
solve();
}
return 0;
}