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.*;
import java.util.*;
 
public class vasily{
 
	class node{
		node arr[];
		int count0;
		int count1;
		boolean isEnd;
 
		public node(){
			this.arr = new node[2];
		//	count =0;
		}
	}
 
	node root;
 
	public vasily(){
		root = new node();
	}
 
	public void insert(ArrayList<Integer> list){
		node temp = root;
		
		//System.out.println(list.toString());
		for (int i=0;i<list.size();i++) {
			if(list.get(i).equals(0)){
			   		temp.count0++;
				}else{
					temp.count1++;
				}
			if(temp.arr[list.get(i)]==null){
				node temp1 = new node();
				temp.arr[list.get(i)]=temp1;
				temp = temp1;
				
			}else{
				temp = temp.arr[list.get(i)];
			//	temp.count++;
			}
			
		}
		if(list.get(list.size()-1).equals(0)){
			   		temp.count0++;
				}else{
					temp.count1++;
				}
		temp.isEnd = true;
	}
 
	public void delete(ArrayList<Integer> list){
		node temp = root;
		boolean flag = true;
		for (int i=0;i<list.size()&&flag;i++) {
			if(list.get(i).equals(1)){
					if (temp.count1>1) {
					temp.count1--;
					temp = temp.arr[list.get(i)];
				}else{
					temp.count1--;
					temp.arr[1] = null;
					flag =false;
				}
			}else{
				if (temp.count0>1) {
				temp.count0--;
				temp = temp.arr[list.get(i)];
				//System.out.println(temp.count+"  "+ i);
			}else{
				temp.count0--;
				temp.arr[0] = null;
				flag =false;
			}
			}
		}
	}
 
	public ArrayList<Integer> maxxor(ArrayList<Integer> list){
		node temp = root;
		boolean flag = true;
		ArrayList<Integer> xori = new ArrayList<Integer>();
 		for (int i=0;i<list.size()&& flag;i++ ) {
 			if (temp.arr[0]==null&&temp.arr[1]==null) {
				flag = false;
			}else{
			if(list.get(i).equals(1)){
				if (temp.arr[0]!=null) {
					temp = temp.arr[0];
					xori.add(0);
				}else{
					temp = temp.arr[1];
					xori.add(1);
				}
			}else{
				if (temp.arr[1]!=null) {
					temp = temp.arr[1];
					xori.add(1);
				}else{
					temp = temp.arr[0];
					xori.add(0);
				}
			}
			}
			
		}
		if (flag) {
			while(temp.arr[0]!=null||temp.arr[1]!=null){
				if (temp.arr[1]!=null) {
					temp = temp.arr[1];
					xori.add(1);
				}else{
					temp = temp.arr[0];
					xori.add(0);
				}
			}
		}
		return xori;
	}
 
	public static void main(String[] args) {
		try{
			BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
			int size = Integer.parseInt(read.readLine());
			vasily obj = new vasily();
			ArrayList<Integer> list1 = new ArrayList<Integer>();
			//System.out.println(list1.size()+" size "+list1.toString());
			for(int i=0;i<32;i++){
				list1.add(0);
			}
			obj.insert(list1);
			for (int i=0;i<size;i++ ) {
				String input = read.readLine();
				String arr[] = input.split(" ");
				String first = arr[0];
				int sec = Integer.parseInt(arr[1]);
				int copy = sec;
				ArrayList<Integer> list  = new ArrayList<Integer>();
				for(int j=0;j<32;j++){
					if (sec%2==0) {
						list.add(0);
					}else{
						list.add(1);
					}
					sec = sec/2;
				}
				Collections.reverse(list);
				//int arrr[] = new int[32];
			//	System.out.println(list.size()+" size "+list.toString());
				if (first.equals("+")) {
					//System.out.println("insert");
					obj.insert(list);
				}else if(first.equals("-")){
					obj.delete(list);
				}else{
					ArrayList<Integer> templ = obj.maxxor(list);
					int target = 0;
				//	System.out.println(templ.size()+" size "+templ.toString());
				//	System.out.println(list.size()+" size "+list.toString());
					for (int j=0;j<templ.size();j++) {
						target += templ.get(j)*((int)Math.pow(2,31-j));
					}
					int ans = copy^target;
					System.out.println(ans);
				}
			}
		}catch (Exception e) {
			System.out.println(e.toString());
 
		}
	}
}
