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>.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;



public class Problem_1 {
	class Node {
		boolean end;
		Node[] next;
		int count = 0;

		Node() {
			next = new Node[2];
		}
	}

	Node root;

	Problem_1() {
		root = new Node();
		Node cur = root;
		for (int i = 0; i < 32; i++) {
			if (cur.next[0] == null)
				cur.next[0] = new Node();
			cur = cur.next[0];
		}
	}

	void insert(String s) {
		s = addZeroes(s);
		int slen = s.length();
		Node cur = root;
		for (int i = 0; i < 32; i++) {
			int nextIdx = Integer.parseInt(s.charAt(i) + "");
			if (cur.next[nextIdx] == null)
				cur.next[nextIdx] = new Node();
			cur = cur.next[nextIdx];
		}
		cur.count++;

		cur.end = true;
	}

	boolean search(String s) {
		s = addZeroes(s);
		int slen = s.length();
		Node cur = root;
		for (int i = 0; i < 32; i++) {
			int nextIdx = Integer.parseInt(s.charAt(i) + "");
			if (cur.next[nextIdx] == null) {
				return false;
			}

			cur = cur.next[nextIdx];
		}
		return cur.end;
	}

	void delete(String s) {
		// if (search(s)) {
		Node cur = root;
		Node deleteFrom = root;
		s = addZeroes(s);
		int index = 0;
		for (int i = 0; i < 32; i++) {
			int nextIdx = Integer.parseInt(s.charAt(i) + "");
			if (cur.next[0] != null && cur.next[1] != null) {
				deleteFrom = cur;
				index = i;
			}
			cur = cur.next[nextIdx];
		}

		if (cur.count > 1) {
			cur.count--;
		} else {
			int value = Integer.parseInt(s.charAt(index) + "");
			deleteFrom.next[value] = null;
		}
	}

	String maxXor(String s) {
		String finalString = "";
		Node cur = root;
		s = addZeroes(s);
		int slen = s.length();
		for (int i = 0; i < 32; i++) {
			int nextIdx = Integer.parseInt(s.charAt(i) + "");
			int idx = 0;
			if (nextIdx == 0)
				idx = 1;
			else
				idx = 0;
			if (cur.next[idx] != null) {
				cur = cur.next[idx];
				finalString += idx;
			} else if (cur.next[nextIdx] != null) {
				cur = cur.next[nextIdx];
				finalString += nextIdx;
			} else {
				return finalString;
			}
		}

		return finalString;
	}

	String addZeroes(String s) {
		int len = s.length();
		int count = 32 - len;
		for (int i = 0; i < count; i++) {
			s = "0" + s;
		}
		return s;
	}

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		Problem_1 trie = new Problem_1();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int count = Integer.parseInt(br.readLine());
		for (int i = 0; i < count; i++) {
			String line[] = br.readLine().split(" ");
			int n = Integer.parseInt(line[1]);
			String binary = Integer.toBinaryString(n);
			if (line[0].equals("+"))
				trie.insert(binary);
			else if (line[0].equals("-"))
				trie.delete(binary);
			else if (line[0].equals("?")) {
				System.out.println(Integer.parseInt(line[1])
						^ Integer.parseInt(trie.maxXor(binary), 2));
			}
		}

	}

}
