#include <bits/stdc++.h>
using namespace std;
// #pragma GCCoptimize("O3")
// #pragma GCCtarget("sse4")
// #pragma GCCoptimize("unroll-loops")
#define vi vector<int>
#define PB push_back
#define vll vector<long long>
#define ll long long
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define ld long double
#define vld vector<double>
#define pll pair<ll, ll>
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
const ll mod = 998244353;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
vector<vi> adj;
vi in, out;
vi val;
int timer;
struct Query {
string type;
ll u, v;
};
struct Trie {
struct Node {
int next[2];
set<int> id;
Node () {
for (int i = 0; i < 2; i++) next[i] = -1;
}
};
vector<Node> adj;
int idx;
Trie () {
adj.PB(Node());
idx = 1;
}
void insert(int x, int node){
int cur = 0;
string s = bitset<31>(x).to_string();
adj[cur].id.insert(node);
for (char c: s){
if (adj[cur].next[c - '0'] == -1){
adj[cur].next[c - '0'] = idx++;
adj.PB(Node());
}
cur = adj[cur].next[c - '0'];
adj[cur].id.insert(node);
}
}
int query(int x, int in, int out){
int cur = 0;
int ret = 0;
int gun = (1 << 30);
string s = bitset<31>(x).to_string();
for (char c: s){
if (adj[cur].next[1 - (c - '0')] == -1){
cur = adj[cur].next[c - '0'];
}
else {
int nxt = adj[cur].next[1 - (c - '0')];
auto itr = adj[nxt].id.lower_bound(in);
if (itr != adj[nxt].id.end() && *itr <= out){
cur = nxt;
ret += gun;
}
else {
cur = adj[cur].next[c - '0'];
}
}
gun /= 2ll;
}
return ret;
}
void trav(int x){
int cur = 0;
string s = bitset<31>(x).to_string();
string check = "";
for (char c: s){
cur = adj[cur].next[c - '0'];
check += c;
cout << check << " -> ";
for (auto elem: adj[cur].id) cout << elem << " ";
cout << "\n";
}
}
};
void dfs(int node) {
in[node] = ++timer;
for (int next: adj[node]){
dfs(next);
}
out[node] = timer;
}
void solve(int tst){
int n;
cin >> n;
adj.assign(n + 1, vi());
in.assign(n + 1, 0ll);
out.assign(n + 1, 0ll);
val.assign(n + 1, 0ll);
timer = 0;
vector<Query> query(n);
int cur = 1;
for (int i = 0; i < n; i++){
cin >> query[i].type >> query[i].u >> query[i].v;
if (query[i].type == "Add") {
adj[query[i].u].PB(++cur);
val[cur] = (query[i].v ^ val[query[i].u]);
}
}
dfs(1);
// for (int i = 1; i <= n; i++){
// cout << i << " " << in[i] << " " << out[i] << " " << val[i] << "\n";
// }
cur = 1;
Trie trie;
trie.insert(0, in[1]);
for (int i = 0; i < n; i++){
if (query[i].type == "Add"){
++cur;
trie.insert(val[cur], in[cur]);
// cout << "INSERT " << val[cur] << " " << cur << "\n";
}
else {
// cout << val[query[i].u] << " " << in[query[i].v] << " " << out[query[i].v] << "\n";
cout << trie.query(val[query[i].u], in[query[i].v], out[query[i].v]) << "\n";
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
// pre();
int tc = 1;
// cin >> tc;
for (int i = 1; i <= tc; i++){
solve(i);
}
return 0;
}