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>.
/**
 * Created by ankeet on 8/11/16.
 */
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class D706 {

    static FastReader in = null;
    static PrintWriter out = null;

    static TrieNode root = null;

    static class TrieNode{
        int val;
        int occ; // number of elements in treenode that go through this node
        TrieNode c0 = null;
        TrieNode c1 = null;
        public TrieNode(int v)
        {
            this.val = v;
        }
    }

    static void add(int val){
        TrieNode ptr = root;
        root.occ++;
        int i = 30;
        while(i>=0)
        {
            if(((1<<i)&val) == 0)
            {
                if(ptr.c0 == null)
                    ptr.c0 = new TrieNode((ptr.val << 1));
                ptr = ptr.c0;
            }
            else
            {
                if(ptr.c1 == null)
                    ptr.c1 = new TrieNode(1 + (ptr.val << 1));
                ptr = ptr.c1;
            }
            ptr.occ++;
            i--;
        }
    }

    static void remove(int val){
        TrieNode ptr = root;
        root.occ--;
        TrieNode parent = null;
        int i = 30;
        while(i>=0)
        {
            parent = ptr;

            if(((1<<i)&val) == 0)
            {
                ptr = ptr.c0;
                if(ptr.occ == 1)
                {
                    parent.c0 = null;
                    return;
                }
            }
            else
            {
                ptr = ptr.c1;
                if(ptr.occ == 1)
                {
                    parent.c1 = null;
                }
            }
            ptr.occ--;
            i--;
        }


    }

    static int maxxor(int val){
        TrieNode ptr = root;
        int i = 30;

        while(i>=0)
        {
            if(((1<<i)&val) == 0)
            {
                if(ptr.c1 != null) ptr = ptr.c1;
                else ptr = ptr.c0;
            }
            else
            {
                if(ptr.c0 != null) ptr = ptr.c0;
                else ptr = ptr.c1;
            }

            i--;
        }
        return ptr.val;
    }






    public static void solve()
    {


        int q = in.nint();

        TreeMap<Integer, Integer> tm = new TreeMap<Integer, Integer>();
        root = new TrieNode(0);
        add(0);
        for(int i=0; i<q; i++)
        {
            char f = in.next().charAt(0);
            int val = in.nint();
            if(f == '+')
            {
                if(tm.containsKey(val))
                {
                    tm.put(val,tm.get(val)+1);
                }
                else
                {
                    tm.put(val,1);
                    add(val);
                }
            }
            if(f == '-')
            {
                if(tm.get(val) == 1)
                {
                    tm.remove(val);
                    remove(val);
                }
                else
                {
                    tm.put(val,tm.get(val)-1);
                }
            }

            if(f == '?')
            {
                int res = maxxor(val);
                out.println(res ^ val);
            }
        }

    }

    public static void main(String[] args)
    {
        in = new FastReader(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.flush();
        out.close();

    }

    static class FastReader {

        BufferedReader read;
        StringTokenizer tokenizer;

        public FastReader(InputStream in)
        {
            read = new BufferedReader(new InputStreamReader(in));
        }

        public String next()
        {
            while(tokenizer == null || !tokenizer.hasMoreTokens())
            {
                try{
                    tokenizer = new StringTokenizer(read.readLine());
                }catch(Exception e){
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nint()
        {
            return Integer.parseInt(next());
        }
        public long nlong()
        {
            return Long.parseLong(next());
        }
        public double ndouble()
        {
            return Double.parseDouble(next());
        }

        public int[] narr(int n)
        {
            int[] a = new int[n];
            for(int i=0; i<n; ++i)
            {
                a[i] = nint();
            }
            return a;
        }

        public long[] nlarr(int n)
        {
            long[] a = new long[n];
            for(int i=0; i<n; ++i)
            {
                a[i] = nlong();
            }
            return a;
        }
    }


}


