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.util.*;
import java.io.*;

public class D_706 {
	
	public static String fix(String s) {
		while(s.length() < 30)
			s = "0" + s;
		return s;
	}
	
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		Trie set = new Trie();
		set.add(fix("0"));
		
		int q = sc.nextInt();
		while(q-->0) {
			char t = sc.nextChar();
			if(t == '+')
				set.add(fix(Integer.toString(sc.nextInt(), 2)));
			else if(t == '-')
				set.delete(fix(Integer.toString(sc.nextInt(), 2)));
			else
				pw.println(Integer.parseInt(set.getMaxXor(fix(Integer.toString(sc.nextInt(), 2))), 2));
		}
		
		pw.flush();
	}

	public static class Node {
		int count;
		Node[] array;
		
		public Node() {
			count = 0;
			array = new Node[2];
		}
	}
	
	public static class Trie {
		
		Node head;
		
		public Trie() {
			head = new Node();
		}
		
		public void add(String s) {
			add(head, s, 0);
		}
		
		public void add(Node curr, String s, int i) {
			curr.count++;
			if(i == s.length())
				return;
			
			int j = s.charAt(i) - '0';
			if(curr.array[j] == null)
				curr.array[j] = new Node();
			add(curr.array[j], s, i + 1);
		}
		
		public void delete(String s) {
			delete(head, s, 0);
		}
		
		public void delete(Node curr, String s, int i) {
			curr.count--;
			if(i == s.length())
				return;
			
			int j = s.charAt(i) - '0';
			delete(curr.array[j], s, i + 1);
			if(curr.array[j].count == 0)
				curr.array[j] = null;
		}
		
		public String getMaxXor(String s) {
			return getMaxXor(head, s, 0);
		}
		
		public String getMaxXor(Node head, String s, int i) {
			if(i == s.length())
				return "";
			
			if(s.charAt(i) == '0')
				if(head.array[1] != null)
					return "1" + getMaxXor(head.array[1], s, i + 1);
				else
					return "0" + getMaxXor(head.array[0], s, i + 1);
			else
				if(head.array[0] != null)
					return "1" + getMaxXor(head.array[0], s, i + 1);
				else
					return "0" + getMaxXor(head.array[1], s, i + 1);
		}
		
	}

	public static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] array = new int[n];
			for (int i = 0; i < n; i++)
				array[i] = nextInt();
			return array;
		}

		public Integer[] nextIntegerArray(int n) throws IOException {
			Integer[] array = new Integer[n];
			for (int i = 0; i < n; i++)
				array[i] = new Integer(nextInt());
			return array;
		}

		public long[] nextLongArray(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++)
				array[i] = nextLong();
			return array;
		}

		public double[] nextDoubleArray(int n) throws IOException {
			double[] array = new double[n];
			for (int i = 0; i < n; i++)
				array[i] = nextDouble();
			return array;
		}

		public static int[] shuffle(int[] a) {
			int n = a.length;
			Random rand = new Random();
			for (int i = 0; i < n; i++) {
				int tmpIdx = rand.nextInt(n);
				int tmp = a[i];
				a[i] = a[tmpIdx];
				a[tmpIdx] = tmp;
			}
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}
