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>.
/*
 * Code Author: Akshay Miterani
 * DA-IICT
 */
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class A {

	static double eps=(double)1e-15;
	static long mod=(int)1e9+7;
	public static void main(String args[]) throws FileNotFoundException, UnsupportedEncodingException{
		InputReader in = new InputReader(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		//----------My Code----------
		int n=in.nextInt();
		HashMap<Integer,Integer> h=new HashMap<>();
		TrieNode root=new TrieNode();
		String tmp="";
		while(tmp.length()<32)
			tmp+="0";
		insertString(root, tmp);
		while(n-->0){
			String s[]=in.nextLine().split(" ");
			int val=Integer.parseInt(s[1]);
			if(s[0].charAt(0)=='+'){
				if(h.containsKey(val)){
					h.put(val, h.get(val)+1);
				}
				else{
					h.put(val, 1);
					String ins=Long.toBinaryString(val);
					while(ins.length()<32){
						ins="0"+ins;
					}
					insertString(root, ins);
				}
			}
			else if(s[0].charAt(0)=='-'){
				if(h.get(val)==1){
					h.remove(val);
					// To be done
					String ins=Long.toBinaryString(val);
					while(ins.length()<32){
						ins="0"+ins;
					}
					//System.out.println(ins);
					//System.out.println(contains(root, ins));
					removeString(root, ins);
					//System.out.println(contains(root, ins));
				}
				else{
					h.put(val, h.get(val)-1);
				}
			}
			else if(s[0].charAt(0)=='?'){
				String ins=Long.toBinaryString(val);
				while(ins.length()<32){
					ins="0"+ins;
				}
				String maxstr=max(root, ins);
				//System.out.println(maxstr);
				long ans=0;
				long xx=1;
				for(int i=maxstr.length()-1;i>=0;i--){
					ans+=(maxstr.charAt(i)-'0')*xx;
					xx*=2;
				}
				out.println(ans);
			}
		}
		
		out.close();
		//---------------The End------------------
	}
	static class TrieNode {
        TrieNode[] children = new TrieNode[2];
        boolean leaf;
        int count=0;
    }

    public static void insertString(TrieNode root, String s) {
        TrieNode cur = root;
        for (char ch : s.toCharArray()) {
        	int x=ch-'0';
            if (cur.children[x] == null) {
                cur.children[x] = new TrieNode();
            }
            cur = cur.children[x];
            cur.count++;
        }
        if(cur!=null)
        	cur.leaf = true;
    }
    
    public static boolean contains(TrieNode root, String s) {
        TrieNode cur = root;
        for (char ch : s.toCharArray()) {
        	int x=ch-'0';
            if (cur.children[x] == null) {
                return false;
            }
            cur = cur.children[x];
        }
        return cur.leaf;
    }
    
    public static void removeString(TrieNode root, String s) {
        TrieNode cur = root;
        //TrieNode par = root;
        for (char ch : s.toCharArray()) {
        	int x=ch-'0';
        	//par=cur;
            TrieNode child = cur.children[x];
            if(child==null)
            	return;
            if(child.count==1){
        		cur.children[x]=null;
        		return;
        	}
        	else{
        		child.count--;
        		cur=child;
        	}
        }
        if(cur!=null)
        	cur.leaf=false;
    }
    
    static String max(TrieNode root, String s){
    	String ret="";
    	TrieNode cur = root;
    	for (char ch : s.toCharArray()) {
        	int x=ch-'0';
            if (cur.children[x^1] != null && cur.children[x^1].count>0) {
                ret+="1";
                cur = cur.children[x^1];
            }
            else if(cur.children[x] != null && cur.children[x].count>0){
            	ret+="0";
            	cur = cur.children[x];
            }
            else{
            	return ret;
            }
        }
    	return ret;
    }
    public static void printSorted(TrieNode node, String s) {
        for (char ch = 0; ch < node.children.length; ch++) {
            TrieNode child = node.children[ch];
            if (child != null)
                printSorted(child, s + ch);
        }
        if (node.leaf) {
            System.out.println(s);
        }
    }
	static class Pair implements Comparable<Pair> {
		int u;
		int v;

		public Pair(int u, int v) {
			this.u = u;
			this.v = v;
		}

		public int hashCode() {
			int hu = (int) (u ^ (u >>> 32));
			int hv = (int) (v ^ (v >>> 32));
			return 31 * hu + hv;
		}

		public boolean equals(Object o) {
			Pair other = (Pair) o;
			return u == other.u && v == other.v;
		}

		public int compareTo(Pair other) {
			return Long.compare(u, other.u) != 0 ? Long.compare(u, other.u) : Long.compare(v, other.v);
		}

		public String toString() {
			return "[u=" + u + ", v=" + v + "]";
		}
	}
	public static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
	static long modulo(long a,long b,long c) {
		long x=1;
		long y=a;
		while(b > 0){
			if(b%2 == 1){
				x=(x*y)%c;
			}
			y = (y*y)%c; // squaring the base
			b /= 2;
		}
		return  x%c;
	}
	static long gcd(long x, long y)
	{
		if(x==0)
			return y;
		if(y==0)
			return x;
		long r=0, a, b;
		a = (x > y) ? x : y; // a is greater number
		b = (x < y) ? x : y; // b is smaller number
		r = b;
		while(a % b != 0)
		{
			r = a % b;
			a = b;
			b = r;
		}
		return r;
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream inputstream) {
			reader = new BufferedReader(new InputStreamReader(inputstream));
			tokenizer = null;
		}

		public String nextLine(){
			String fullLine=null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine=reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}  
