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>.
from collections import defaultdict




class Trie():

    def __init__(self,value):

        self.value = value
        self.left = None
        self.right = None
        self.terminal = False
        self.par = None
        self.child = 0




def insert(n,head):

    cur_node = head

    for i in range(31,-1,-1):
        z = (n>>i)&1
        if z == 0:
            if cur_node.left == None:

                cur_node.left = Trie(z)
                cur_node.left.par = cur_node
                cur_node.child+=1

            cur_node = cur_node.left
        else:
            if cur_node.right == None:
                cur_node.right = Trie(z)
                cur_node.right.par = cur_node
                cur_node.child+=1
            cur_node = cur_node.right

    cur_node.terminal = True

def maxi(n,head):

    cur_node = head
    cur_xor = 0
    for i in range(31,-1,-1):
        z = (n>>i)&1
        if cur_node == None:
            break
        if z == 0:

            if cur_node.right!=None:
                cur_node = cur_node.right
                cur_xor+=pow(2,i)
            else:

                cur_node = cur_node.left
        if z == 1:
            if cur_node.left!=None:
                cur_node = cur_node.left
                cur_xor+=pow(2,i)
            else:

                cur_node = cur_node.right



    return cur_xor

def delete(head,n):
    cur_node = head

    for i in range(31,-1,-1):
        z = (n>>i)&1
        if z == 0:
            if cur_node.left == None:
                cur_node.left = Trie(z)
            cur_node = cur_node.left
        else:
            if cur_node.right == None:
                cur_node.right = Trie(z)
            cur_node = cur_node.right

    # print(cur_node.value)
    z = cur_node.value
    temp = cur_node.par
    if cur_node.left!=None:
        cur_node.left = None
    if cur_node.right!=None:
        cur_node.right = None
    if z == 0:
        if temp.left != None:
            if temp.left.value == 0:
                temp.left = None
    elif z == 1:
        if temp.right != None:
            if temp.right.value == 1:
                temp.right = None
    del(cur_node)
    cur_node = temp





    while cur_node.par!=None:


            if cur_node.child-1 == 0:
                if cur_node.terminal == False:
                    z = cur_node.value
                    temp = cur_node.par
                    if cur_node.left!=None:
                        cur_node.left = None
                    if cur_node.right!=None:
                        cur_node.right = None

                    if z == 0:
                        if temp.left != None:
                            if temp.left.value == 0:
                                temp.left = None
                    elif z == 1:
                        if temp.right != None:
                            if temp.right.value == 1:
                                temp.right = None


                    del(cur_node)

                    cur_node = temp
                    if cur_node == head:


                         cur_node.child-=1
                         break




                else:

                    break
            else:

                cur_node.child-=1
                break










hash = defaultdict(int)

head = Trie('y')
head.par = None



insert(0,head)

ans = []
q = int(input())

for i in range(q):

    a,b = map(str,input().split())
    b = int(b)

    if a == '+':
        hash[b]+=1
        if hash[b] == 1:
            insert(b,head)
    if a == '-':
        hash[b]-=1
        if hash[b] == 0:

            delete(head,b)

    if a == '?':
        ans.append(maxi(b,head))


print(*ans)
















