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.util.NavigableMap;
import java.util.TreeMap;

import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.Charset;

public class VMulti
{
	public static void main(String[] args) throws IOException
	{
		//BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(str.getBytes(Charset.forName("UTF-8"))));
		BufferedInputStream in = new BufferedInputStream(System.in);
		int q = nextInt(in);
		NavigableMap<Integer, Integer> ints = new TreeMap<Integer, Integer>();
		ints.put(0, 1);
		StringBuilder sb = new StringBuilder();
		for (int k = 0; k < q; k++)
		{
			String instr = nextInstr(in);
			if (instr.equals("+"))
			{
				int x = nextInt(in);
				if (ints.containsKey(x))
				{
					ints.put(x, ints.get(x) + 1);
				}
				else
				{
					ints.put(x, 1);
				}
			}
			else if (instr.equals("-"))
			{
				int x = nextInt(in);
				if (ints.get(x) == 1)
				{
					ints.remove(x);
				}
				else
				{
					ints.put(x, ints.get(x) - 1);
				}
			}
			else if (instr.equals("?"))
			{
				int x = nextInt(in);
				int y = maxXor(x, ints);
				sb.append((x ^ y) + System.lineSeparator());
			}
		}
		System.out.println(sb);
	}
	
	public static int maxXor(int x, NavigableMap<Integer, Integer> ints)
	{
		// leading 0's of x
		int pow = pow2Gtr(x);
		int biggest = ints.lastEntry().getKey();
		int lower = biggest & ~(pow - 1); // & with mask of leading 0's
		ints = ints.tailMap(lower, true);
		if (biggest == ints.firstEntry().getKey())
		{
			return biggest;
		}
		// leading 1's of x
		// find last leading 1, mask leading 1's
		int onesMask = 0;
		if (pow != 1)
		{
			pow /= 2;
			onesMask += pow;
		}
		while (pow != 1 && (((pow/2) & x) != 0))
		{
			pow /= 2;
			onesMask += pow;
		}
		int smallest = ints.firstEntry().getKey();
		int upper = smallest | (pow - 1); // | with mask of bits after leading 1's
		ints = ints.headMap(upper, true);
		if (smallest == ints.lastEntry().getKey())
		{
			return smallest;
		}
		// keep going
		return maxXor(x & ~onesMask, ints);
	}
	
	public static int pow2Gtr(int x)
	{
		int i = 1;
		while (i <= x)
		{
			i *= 2;
		}
		return i;
	}
	
	public static int nextInt(BufferedInputStream in) throws IOException
	{
		int next = 0;
		boolean haveNext = false;
		int b;
		while ((b = in.read()) != -1)
		{
			if ('0' <= b && b <= '9')
			{
				next = 10*next + (b - '0');
				haveNext = true;
			}
			else if (haveNext)
			{
				break;
			}
		}
		return next;
	}
	
	public static String nextInstr(BufferedInputStream in) throws IOException
	{
		StringBuilder sb = new StringBuilder();
		boolean haveNext = false;
		int b;
		while ((b = in.read()) != -1)
		{
			if (b == '+' || b == '-' || b == '?')
			{
				sb.append((char)b);
				haveNext = true;
			}
			else if (haveNext)
			{
				break;
			}
		}
		return sb.toString();
	}
}