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


public class CF706D {
	
	public static String leadZero(String str)
	{
		StringBuilder sb = new StringBuilder();
		int i = 0;
		for(i=0;i<31-str.length();i++)
			sb.append("0");
		for(int j=0;j<str.length();j++)
			sb.append(str.charAt(j));
		return sb.toString();
	}
	
	static class binaryTree
	{
		private static Node root;
		static class Node
		{
			int val;
			Node left;
			Node right;
			Node(int a)
			{
				this.val = a;
			}
		}
		binaryTree()	{
			root = new Node(0);
			Node cur = root;
			for(int i=1;i<31;i++)
			{
				cur.left = new Node(0);
				cur = cur.left;
			}
			//Print All Left
			Node cr = root;
			/*for(int i=0;i<31;i++)
			{
				System.out.print(cr.val);
				cr = cr.left;
			}
			System.out.println();*/
		}
		public static void add(String str)
		{
			Node cur = root;
			for(int i=1;i<31;i++)
			{
				char c = str.charAt(i);
				//System.out.print(c);
				if(c=='0')
				{
					if(cur.left==null)
					{
						cur.left = new Node(0);
						cur = cur.left;
					}
					else
					{
						cur = cur.left;
					}
				}
				else
				{
					if(cur.right==null)
					{
						cur.right = new Node(1);
						cur = cur.right;
					}
					else
					{
						cur = cur.right;
					}
				}
			}
			//System.out.println();
		}
		public static void remove(String str)
		{
			Node cur = root;
			Node split = new Node(0);
			int splitIdx = 0;
			boolean l = true;
			for(int i=1;i<31;i++)
			{
				char c = str.charAt(i);
				if(cur.left!=null&&cur.right!=null)
				{
					split = cur;
					splitIdx = i;
				}
				if(c=='1')
				{
					cur = cur.right;
					l=false;
				}
				else
				{
					cur = cur.left;
					l=true;
				}
			}
			/*if(l==false)
				split.right=null;
			else
				split.left=null;*/
			//System.out.println("sptidx"+splitIdx);
			if(splitIdx!=0)
			{
				if(str.charAt(splitIdx)=='1')
				{
					split.right=null;
					//System.out.println("I");
				}
				else
					split.left=null;
					
			}
		}
		public static int maxXOR(String str)
		{
			Node cur = root;
			StringBuilder sb = new StringBuilder("0");
			for(int i=1;i<31;i++)
			{
				char tmp = str.charAt(i);
				if(tmp=='0')
				{
					if(cur.right!=null)
					{
						cur = cur.right;
						sb.append("1");
					}
					else if(cur.left!=null)
					{
						cur = cur.left;
						sb.append("0");
					}
				}
				else
				{
					if(cur.left!=null)
					{
						cur = cur.left;
						sb.append("0");
					}
					else if(cur.right!=null)
					{
						cur = cur.right;
						sb.append("1");
					}
				}
			}
			//System.out.println(sb.toString());
			//System.out.println(Integer.parseInt(sb.toString(),2));
			return Integer.parseInt(sb.toString(),2);
		}
	}
	
	//Driver Method	
	public static void main(String[] args) {
			FastReader fr = new FastReader();
			int q = fr.nextInt();
			HashMap<Integer,Integer> hm = new HashMap<Integer,Integer>();
			binaryTree bt = new binaryTree();
			for(int i=0;i<q;i++)
			{
				char tmp = fr.nextChar();
				int cint = fr.nextInt();
				String str = leadZero(Integer.toBinaryString(cint));
				//System.out.println(str);
				switch(tmp)
				{
				case '+':
					if(hm.containsKey(cint))
					{
						int tval = hm.remove(cint);
						hm.put(cint,++tval);
					}
					else
					{
						hm.put(cint,1);
						bt.add(str);
					}
					break;
				case '-':
					if(hm.containsKey(cint)&&hm.get(cint)==1)
					{
						hm.remove(cint);
						bt.remove(str);
					}
					else
					{
						hm.put(cint, (hm.remove(cint)-1));
					}
					break;
				case '?':
					int tmpInt = bt.maxXOR(str);
					System.out.println(tmpInt^cint);
					break;
				}
				/*System.out.println("Hash Map Values");
				for (Map.Entry<Integer, Integer> entry : hm.entrySet()) {
				    System.out.println(entry.getKey()+" : "+entry.getValue());
				}*/
			}
	}

	// IO
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

		private String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					System.out.println(e);
				}
			}
			return st.nextToken();
		}

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

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

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

		public Float nextFloat() {
			return Float.parseFloat(next());
		}
		
		public char nextChar() {
			return next().charAt(0);
		}

		public String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				System.out.println(e);
			}
			return str;
		}
	}
}