#include <bits/stdc++.h>
using namespace std;
long long trie[6200000][2], mark[6200000][2], sz = 0;
vector<long long> bin;
void insrt(string s) {
  long long v = 0;
  for (long long i = 0; i < s.size(); ++i) {
    long long c = s[i] - '0';
    if (trie[v][c] == -1) trie[v][c] = ++sz;
    mark[v][c]++;
    v = trie[v][c];
  }
}
void dlt(string s) {
  long long v = 0;
  for (long long i = 0; i < s.size(); ++i) {
    long long c = s[i] - '0';
    mark[v][c]--;
    v = trie[v][c];
  }
}
void srch(string s) {
  long long v = 0;
  for (long long i = 0; i < s.size(); ++i) {
    long long c = s[i] - '0';
    if (trie[v][c] == -1 || mark[v][c] < 1) c ^= 1;
    bin.push_back(c);
    v = trie[v][c];
  }
}
long long dec() {
  long long val = 1, sum = 0;
  for (long long i = bin.size() - 1; i >= 0; --i) {
    if (bin[i] == 1) sum += val;
    val *= 2;
  }
  return sum;
}
void clr() {
  memset(trie, -1, sizeof(trie));
  memset(mark, 0, sizeof(mark));
  sz = 0;
}
int main() {
  long long q, n;
  char ch;
  cin >> q;
  clr();
  string s;
  s = bitset<31>(0).to_string();
  insrt(s);
  while (q--) {
    cin >> ch >> n;
    s = bitset<31>(n).to_string();
    if (ch == '+') insrt(s);
    if (ch == '-') dlt(s);
    if (ch == '?') {
      long long xr = n ^ 1073741823;
      string ss = bitset<31>(xr).to_string();
      srch(ss);
      long long val = dec();
      bin.clear();
      val ^= n;
      cout << val << endl;
    }
  }
}
