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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;


public class May {
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct 

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}


  static class TrieNode {
	    char ch; 
	    boolean isEnd; 
	    int count;  
	    LinkedList<TrieNode> childList; 
	 
	    /* Constructor */
	    public TrieNode(char c){
	        childList = new LinkedList<TrieNode>();
	        isEnd = false;
	        ch = c;
	        count = 0;
	    }  
	    public TrieNode next(char c){
	        if (childList != null)
	            for (TrieNode child : childList)
	                if (child.ch == c)
	                    return child;
	        return null;
	    }
	}
	 
	static class Trie
	{
	    private TrieNode root;
	    
	    public Trie(){
	        root = new TrieNode(' '); 
	    }
	     
	    public void insert(String word){
	        if (search(word) == true) 
	            return;        
	        TrieNode current = root; 
	        for (char ch : word.toCharArray() )
	        {
	            TrieNode child = current.next(ch);
	            if (child != null)
	                current = child;
	            else 
	            {
	                 current.childList.add(new TrieNode(ch));
	                 current = current.next(ch);
	            }
	            current.count++;
	        }
	        current.isEnd = true;
	    }
	    /* Function to search for word */
	    public boolean search(String word)
	    {
	        TrieNode current = root;  
	        for (char ch : word.toCharArray() )
	        {
	            if (current.next(ch) == null)
	                return false;
	            else
	                current = current.next(ch);
	        }      
	        if (current.isEnd == true) 
	            return true;
	        return false;
	    }
	    /* Function to remove a word */
	    public void remove(String word)
	    {
	        if (search(word) == false)
	        {
	            System.out.println(word +" does not exist in trie\n");
	            return;
	        }             
	        TrieNode current = root;
	        for (char ch : word.toCharArray()) 
	        { 
	            TrieNode child = current.next(ch);
	            if (child.count == 1) 
	            {
	                current.childList.remove(child);
	                return;
	            } 
	            else 
	            {
	                child.count--;
	                current = child;
	            }
	        }
	        current.isEnd = false;
	    }
	   
	    public long find(String word) {
	    	long ans = 0;
	    	int i = 0;
	    	TrieNode current = root;
	    	for(char ch : word.toCharArray()) {
	    		char c = (char)((ch-'0')^1+'0');
	    		
	    		TrieNode temp = current.next(c);
	    		if(temp == null) {
	    			current = current.next(ch);
	    			ans+=Math.pow(2,31-i++)*(ch-'0');
	    		}else {
	    			current = temp;
	    			ans+=Math.pow(2,31-i++)*(c-'0');
	    		}
	    	}
	    
	    	return ans;
	    }
	}    
	 
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//Scanner sc = new Scanner(System.in);
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		Map<Integer,Integer> freq = new HashMap<>();
		Trie t = new Trie();
		t.insert(atoi(0));
		add(freq,0);
		while(n-->0) {
			char c = sc.next().charAt(0);
			int x = sc.nextInt();
			String num = atoi(x);
			switch(c) {
			case '+' : if(!freq.containsKey(x))
				           t.insert(num); 
				           add(freq,x);
			break;
			case '-' : if(freq.get(x) == 1) 
				          t.remove(num);
			               delete(freq,x);   
			break;
			case '?' : out.println(x^t.find(num));
			break;	
			}
		}
		out.close();
	}

	private static String atoi(int n) {
		char[] str = new char[32];
		Arrays.fill(str,'0');
		for(int i=31;i>=0 && n>0;--i) {
			if((n&1) == 1)
				str[i] = '1';
			else str[i] = '0';
			n>>=1;
		}
		return new String(str);
	}
	private static void add(Map<Integer, Integer> map, int i) {
		// TODO Auto-generated method stub
		if(map.containsKey(i)) map.put(i, map.get(i)+1);
		else map.put(i, 1);
		
	}
	private static void delete(Map<Integer, Integer> map, int i) {
		if(map.containsKey(i)) {
			if(map.get(i) == 1) map.remove(i);
			else map.put(i, map.get(i)-1);
		}
		
	}
}