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.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;


public class fouth {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		InputReader in=new InputReader(System.in);
		OutputWriter out=new OutputWriter(System.out);
		
	int par[]=new int[10000000];
	int left[]=new int[10000000];
	int right[]=new int[10000000];
	int count[]=new int[10000000];
	int pow[]=new int[31];
	pow[1]=2;
	pow[0]=1;
	for(int i=2;i<=30;i++){
		pow[i]=pow[i-1]*2;
	}
	int total=1;
	HashMap<Integer, Integer> hmp=new HashMap<Integer, Integer>();
	
	Arrays.fill(par,-1 );
	Arrays.fill(left,-1 );
	Arrays.fill(right,-1 );
	
	
	String s="000000000000000000000000000000";
	
	
	
	{
		int x=0;
		hmp.put(x, 1);
		
		String b=Integer.toBinaryString(x);
		b=s.substring(0,30-b.length())+b;
		
		int pointer=0;
		for(int i=0;i<30;i++){
			int c=b.charAt(i);
			if(c=='0'){
				count[pointer]++;
				int l=left[pointer];
				
				if(l==-1){
					par[total]=pointer;
					
					left[pointer]=total++;
				}
				pointer=left[pointer];
			//	out.printLine(x+" l"+" "+pointer);
				
			}
			else{
				count[pointer]++;
				int r=right[pointer];
				if(r==-1){
					par[total]=pointer;
					right[pointer]=total++;
				}
				pointer=right[pointer];
		//		out.printLine(x+" r"+" "+pointer);
			}
			
			
		}
		count[pointer]++;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	int q=in.readInt();
	
	
	while(q>0){
		
		String ty=in.readString();
		int x=in.readInt();
		if(ty.equals("+")){
			if(hmp.containsKey(x)){
				hmp.put(x, hmp.get(x)+1);
				
			}else{
				hmp.put(x, 1);
				
				String b=Integer.toBinaryString(x);
				b=s.substring(0,30-b.length())+b;
				
				int pointer=0;
				for(int i=0;i<30;i++){
					int c=b.charAt(i);
					if(c=='0'){
						count[pointer]++;
						int l=left[pointer];
						
						if(l==-1){
							par[total]=pointer;
							
							left[pointer]=total++;
						}
						pointer=left[pointer];
					//	out.printLine(x+" l"+" "+pointer);
						
					}
					else{
						count[pointer]++;
						int r=right[pointer];
						if(r==-1){
							par[total]=pointer;
							right[pointer]=total++;
						}
						pointer=right[pointer];
				//		out.printLine(x+" r"+" "+pointer);
					}
					
					
				}
				count[pointer]++;
			}
			
		}
		if(ty.equals("-")){
		//	out.printLine(x);
			int v=hmp.get(x);
			
			if(v==1){
				hmp.remove(x);
				

				String b=Integer.toBinaryString(x);
				b=s.substring(0,30-b.length())+b;
			//	out.printLine(b+" "+x);
				int pointer=0;
				for(int i=0;i<30;i++){
					int c=b.charAt(i);
					//out.printLine(i+" "+pointer);
					if(c=='0'){
						int l=left[pointer];
						if(l==-1){
							break;
						}
						else{
							pointer=left[pointer];
						}
						
					}
					else{
						int r=right[pointer];
						if(r==-1){
						
						break;
						}
						else{
						pointer=right[pointer];}
					}
					
					
				}
				
				int cc=pointer;
				while(par[cc]!=-1){
			//		out.printLine(cc+" "+count[cc]);
					if(count[cc]==1){
						if(cc==left[par[cc]])
						left[par[cc]]=-1;
						else
						right[par[cc]]=-1;
					//	
						
					}
					count[cc]--;
					cc=par[cc];
				
				}
				
				
				
			}
			else{
				hmp.put(x, v-1);
			}
			
			
		}
		if(ty.equals("?")){
			
			String b=Integer.toBinaryString(x);
			b=s.substring(0,30-b.length())+b;
			int pointer=0;
			int xor=0;
			for(int i=0;i<30;i++){
				int c=b.charAt(i);
				if(c=='0'){
					//count[pointer]++;
					int l=right[pointer];
					if(l==-1){
						//par[total]=pointer;
						l=left[pointer];
						if(l==-1)break;
						else{
							pointer=left[pointer];
						}
						
						
						//left[pointer]=total++;
					}
					else{
					pointer=right[pointer];
					xor=xor+pow[30-i-1];
					}
				}
				else{
					//count[pointer]++;
					int r=left[pointer];
					if(r==-1){
						//par[total]=pointer;
						//right[pointer]=total++;
						r=right[pointer];
						if(r==-1)
						break;
						else{
							pointer=right[pointer];
						}
					}
					else{
					pointer=left[pointer];
					xor=xor+pow[30-i-1];}
				}
				
				
			}
			out.printLine(xor);
		}
		
		
		q--;
	}
	
	
	out.close();
	
		

	}

}


class InputReader {
	 
	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

class OutputWriter {
	private final PrintWriter writer;

	public OutputWriter(OutputStream outputStream) {
		writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
	}

	public OutputWriter(Writer writer) {
		this.writer = new PrintWriter(writer);
	}

	public void print(Object...objects) {
		for (int i = 0; i < objects.length; i++) {
			if (i != 0)
				writer.print(' ');
			writer.print(objects[i]);
		}
	}

	public void printLine(Object...objects) {
		print(objects);
		writer.println();
	}

	public void close() {
		writer.close();
	}

	public void flush() {
		writer.flush();
	}

	}

class IOUtils {

	public static int[] readIntArray(InputReader in, int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readInt();
		return array;
	}

	}