#include <bits/stdc++.h>
using namespace std;
class Node {
 public:
  Node* one;
  Node* zero;
  bool initOne;
  bool initZero;
  int depth;
  int dup;
  Node(int depth) {
    this->depth = depth;
    initOne = false;
    initZero = false;
    dup = 0;
  }
};
void insert(int x, Node* cur) {
  while (cur->depth > 0) {
    if (x >= 1 << (cur->depth - 1)) {
      x -= 1 << (cur->depth - 1);
      if (cur->initOne == false) {
        cur->one = new Node(cur->depth - 1);
        cur->initOne = true;
      }
      cur = cur->one;
      cur->dup += 1;
    } else {
      if (cur->initZero == false) {
        cur->zero = new Node(cur->depth - 1);
        cur->initZero = true;
      }
      cur = cur->zero;
      cur->dup += 1;
    }
  }
}
void remove(int x, Node* cur) {
  while (cur->depth > 1) {
    if (x >= 1 << (cur->depth - 1)) {
      x -= 1 << (cur->depth - 1);
      cur = cur->one;
    } else {
      cur = cur->zero;
    }
  }
  if (x % 2 == 0) {
    cur->zero->dup -= 1;
    if (cur->zero->dup == 0) {
      delete cur->zero;
      cur->initZero = false;
    }
  } else {
    cur->one->dup -= 1;
    if (cur->one->dup == 0) {
      delete cur->one;
      cur->initOne = false;
    }
  }
}
int find(int x, Node* cur) {
  if (cur->depth == 0) {
    return 0;
  }
  int need = 0;
  int newX = x % (1 << (cur->depth - 1));
  if (x < 1 << (cur->depth - 1)) {
    need = 1;
  }
  int ans = -1;
  if (need == 0 && cur->initZero == true) {
    ans = find(newX, cur->zero);
  } else if (need == 1 && cur->initOne == true) {
    ans = find(newX, cur->one);
  }
  if (ans != -1) {
    return ans + need * (1 << (cur->depth - 1));
  }
  need = (need + 1) % 2;
  if (need == 0 && cur->initZero == true)
    ans = find(newX, cur->zero);
  else if (need == 1 && cur->initOne == true)
    ans = find(newX, cur->one);
  if (ans == -1)
    return -1;
  else
    return ans + need * (1 << (cur->depth - 1));
}
int main() {
  int q;
  scanf("%d", &q);
  Node* start = new Node(31);
  insert(0, start);
  for (int i = 0; i < q; i++) {
    char* next = new char[1];
    int n;
    scanf("%s", next);
    scanf("%d", &n);
    if (next[0] == '+') {
      insert(n, start);
    } else if (next[0] == '-') {
      remove(n, start);
    } else {
      int ans = find(n, start);
      printf("%d\n", ans ^ n);
    }
  }
  return 0;
}

### Prompt

Create a solution in Cpp for the following problem:

Author has gone out of the stories about Vasiliy, so here is just a formal task description.

You are given q queries and a multiset A, initially containing only integer 0. There are three types of queries:

  1. "+ x" — add integer x to multiset A.
  2. "- x" — erase one occurrence of integer x from multiset A. It's guaranteed that at least one x is present in the multiset A before this query.
  3. "? x" — you are given integer x and need to compute the value <image>, i.e. the maximum value of bitwise exclusive OR (also know as XOR) of integer x and some integer y from the multiset A.



Multiset is a set, where equal elements are allowed.

Input

The first line of the input contains a single integer q (1 ≤ q ≤ 200 000) — the number of queries Vasiliy has to perform.

Each of the following q lines of the input contains one of three characters '+', '-' or '?' and an integer xi (1 ≤ xi ≤ 109). It's guaranteed that there is at least one query of the third type.

Note, that the integer 0 will always be present in the set A.

Output

For each query of the type '?' print one integer — the maximum value of bitwise exclusive OR (XOR) of integer xi and some integer from the multiset A.

Example

Input

10
+ 8
+ 9
+ 11
+ 6
+ 1
? 3
- 8
? 3
? 8
? 11


Output

11
10
14
13

Note

After first five operations multiset A contains integers 0, 8, 9, 11, 6 and 1.

The answer for the sixth query is integer <image> — maximum among integers <image>, <image>, <image>, <image> and <image>.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
class Node {
 public:
  Node* one;
  Node* zero;
  bool initOne;
  bool initZero;
  int depth;
  int dup;
  Node(int depth) {
    this->depth = depth;
    initOne = false;
    initZero = false;
    dup = 0;
  }
};
void insert(int x, Node* cur) {
  while (cur->depth > 0) {
    if (x >= 1 << (cur->depth - 1)) {
      x -= 1 << (cur->depth - 1);
      if (cur->initOne == false) {
        cur->one = new Node(cur->depth - 1);
        cur->initOne = true;
      }
      cur = cur->one;
      cur->dup += 1;
    } else {
      if (cur->initZero == false) {
        cur->zero = new Node(cur->depth - 1);
        cur->initZero = true;
      }
      cur = cur->zero;
      cur->dup += 1;
    }
  }
}
void remove(int x, Node* cur) {
  while (cur->depth > 1) {
    if (x >= 1 << (cur->depth - 1)) {
      x -= 1 << (cur->depth - 1);
      cur = cur->one;
    } else {
      cur = cur->zero;
    }
  }
  if (x % 2 == 0) {
    cur->zero->dup -= 1;
    if (cur->zero->dup == 0) {
      delete cur->zero;
      cur->initZero = false;
    }
  } else {
    cur->one->dup -= 1;
    if (cur->one->dup == 0) {
      delete cur->one;
      cur->initOne = false;
    }
  }
}
int find(int x, Node* cur) {
  if (cur->depth == 0) {
    return 0;
  }
  int need = 0;
  int newX = x % (1 << (cur->depth - 1));
  if (x < 1 << (cur->depth - 1)) {
    need = 1;
  }
  int ans = -1;
  if (need == 0 && cur->initZero == true) {
    ans = find(newX, cur->zero);
  } else if (need == 1 && cur->initOne == true) {
    ans = find(newX, cur->one);
  }
  if (ans != -1) {
    return ans + need * (1 << (cur->depth - 1));
  }
  need = (need + 1) % 2;
  if (need == 0 && cur->initZero == true)
    ans = find(newX, cur->zero);
  else if (need == 1 && cur->initOne == true)
    ans = find(newX, cur->one);
  if (ans == -1)
    return -1;
  else
    return ans + need * (1 << (cur->depth - 1));
}
int main() {
  int q;
  scanf("%d", &q);
  Node* start = new Node(31);
  insert(0, start);
  for (int i = 0; i < q; i++) {
    char* next = new char[1];
    int n;
    scanf("%s", next);
    scanf("%d", &n);
    if (next[0] == '+') {
      insert(n, start);
    } else if (next[0] == '-') {
      remove(n, start);
    } else {
      int ans = find(n, start);
      printf("%d\n", ans ^ n);
    }
  }
  return 0;
}

```