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;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.StringTokenizer;


public class D706 {
	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;
	
	public String nextToken() throws IOException {
	    while (in == null || !in.hasMoreTokens()) {
	        in = new StringTokenizer(br.readLine());
	    }
	    return in.nextToken();
	}
	
	public int nextInt() throws IOException {
	    return Integer.parseInt(nextToken());
	}

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

	public double nextDouble() throws IOException {
	    return Double.parseDouble(nextToken());
	}
	
	public void solve() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);

        int cases = nextInt();
        
        Trie t = new Trie();
        HashMap <Integer,Integer> map = new HashMap<Integer,Integer>();
        map.put(0,1);
        
        for(int i = 0 ; i < cases; i++) {
        	String token = nextToken();
        	int value = nextInt();
        	
        	if(token.equals("+")) {
        		if(map.containsKey(value)) {
        			map.put(value, map.get(value)+1);
        		} else {
        			map.put(value,1);
        			t.addNode(toBits(value));
        		}
        	}
        	if(token.equals("-")) {
        		if(map.get(value) == 1) {
        			map.remove(value);
        			t.deleteNode(toBits(value));
        		} else {
        			map.put(value,map.get(value)-1);
        		}
        	} 
        	if(token.equals("?")) {
        		boolean [] result = t.traverse(toBits(value));
        		long output = 0L;
        		for(int j = 0 ; j < result.length ; j++) {
        			output = output << 1;
        			if(result[j]) {
        				output = output | 1;
        			}
        		}
        		out.println(output);
        	}
        }
        out.close();
	}
	
	public boolean[] toBits(int value) {
		boolean [] bits = new boolean[32];
		int index = bits.length - 1; 
		while(value > 0) {
			bits[index--] = value % 2 == 1; 
			value /= 2;
		}
		return bits;
	}
	public static void main (String [] args) throws IOException {
		new D706().solve();
	}
	
	class Trie {
		Node root;
		
		public Trie() {
			root = new Node();
			addNode(new boolean[32]);
		}
		
		public void addNode(boolean [] bits) {
			Node current = root;
			for(int i = 0 ; i < bits.length; i++) {
				if(!bits[i]) {
					if(current.left == null) {
						current = current.addLeft();
					} else {
						current = current.left;
					}
				} else {
					if(current.right == null) {
						current = current.addRight();
					} else {
						current = current.right;
					}
				}
			}
		}
		
		public void deleteNode(boolean [] bits) {
			Node current = root;
			for(int i = 0 ; i < bits.length - 1; i++) {
				if(bits[i])
					current = current.right;
				else
					current = current.left;
			}
			if(bits[bits.length-1])
				current.right = null;
			else
				current.left = null;
			
			while(current != null) {
				if(current.left != null || current.right != null)
					break;
				else {
					Node parent = current.parent;
					if(parent.left == current) {
						parent.left = null;
						current = parent;
					} else {
						parent.right = null;
						current = parent;
					}
				}
			}
		}
		
		public boolean[] traverse(boolean [] bits) {
			Node current = root;
			boolean [] result = new boolean[32];
			for(int i = 0 ; i < bits.length ; i++) {
				if(bits[i] && current.left != null) {
					result[i] = true;
					current = current.left;
				}else
				if(!bits[i] && current.right != null) {
					result[i] = true;
					current = current.right;
				}
				else {
					if(bits[i])
						current = current.right;
					else
						current = current.left;
				}
			}
			return result;
		}
	}
	
	class Node {
		Node left;
		Node right;
		Node parent;
		
		Node addLeft() {
			left = new Node();
			left.parent = this;
			return left;
		}
		Node addRight() {
			right = new Node();
			right . parent = this;
			return right;
		}
	}
}
