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.StringTokenizer;

public class VasiliysMultiset {

    public static class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int q = fs.nextInt();

        BitTrie t = new BitTrie(); // starts with initial value 0
        t.add(0);

        StringBuffer result = new StringBuffer();
        for (int i = 0; i < q; ++i) {
            char c = fs.nextToken().charAt(0);
            long x = fs.nextInt();
            if (c == '+') {
                t.add(x);
            }
            else if (c == '-') {
                t.remove(x);
            }
            else {
                long res = t.max(x);
                result.append(res);
                result.append('\n');
            }
        }
        System.out.println(result);
    }

    private static class BitTrie {

        private class Node {
            int elements = 0;
            int value;
            Node left, right, parent;

            public Node(int v) {
                value = v;
                elements++;
            }

            public void increase() {
                elements++;
            }

            public void decrease() {
                elements--;
            }
        }

        private Node root;
        public BitTrie() {
            root = new Node(-1); // dummy node
        }

        private int[] toBits(long x) {
            int[] res = new int[32];

            int start = 31;
            while (x > 0) {
                res[start] = (int) (x % 2);
                x /= 2;
                start--;
            }

            return res;
        }

        private long max(long x) {
            int[] result = new int[32];
            int[] bits = toBits(x);

            Node tmpRoot = root;
            for (int i = 0; i < 32; ++i) {
                int lookFor = bits[i] == 0? 1: 0;
                if (lookFor == 0) {
                    if (tmpRoot.left != null) {
                        tmpRoot = tmpRoot.left;
                        result[i] = 1;
                    }
                    else {
                        tmpRoot = tmpRoot.right;
                    }
                }
                else {
                    if (tmpRoot.right != null) {
                        tmpRoot = tmpRoot.right;
                        result[i] = 1;
                    }
                    else {
                        tmpRoot = tmpRoot.left;
                    }
                }
            }

            long finalNumber = 0;
            for (int i = 0; i < 32; ++i) {
                finalNumber += (result[i] == 1? Math.pow(2, 31 - i): 0);
            }

            return finalNumber;
        }

        private void remove(long x) {
            int[] bits = toBits(x);

            Node toRemoveNode = null;
            boolean wholeRemoval = false;
            Node tmpRoot = root;
            for (int i = 0; i < 32; ++i) {
                if (bits[i] == 0) {
                    tmpRoot = tmpRoot.left;
                }
                else {
                    tmpRoot = tmpRoot.right;
                }
                if (i == 31) {
                    tmpRoot.decrease();
                    if (tmpRoot.elements == 0) {
                        toRemoveNode = tmpRoot;
                        wholeRemoval = true;
                    }
                }
            }

            if (wholeRemoval) {
                int times = 0;
                while (true) {
                    times++;
                    if (toRemoveNode.parent.left == null) {
                        toRemoveNode.parent.right = null;
                    } else if (toRemoveNode.parent.right == null) {
                        toRemoveNode.parent.left = null;
                    } else {
                        if (toRemoveNode.parent.left == toRemoveNode) {
                            toRemoveNode.parent.left = null;
                        }
                        else {
                            toRemoveNode.parent.right = null;
                        }
                        break;
                    }
                    toRemoveNode = toRemoveNode.parent;
                }
            }
        }

        private void add(long x) {
            int[] bits = toBits(x);

            Node tmpRoot = root;

            for (int i = 0; i < 32; ++i) {
                Node n = new Node(bits[i]);
                boolean newNode = false;
                if (bits[i] == 0) {
                    if (tmpRoot.left != null) {
                        tmpRoot = tmpRoot.left;
                    } else {
                        tmpRoot.left = n;
                        n.parent = tmpRoot;
                        tmpRoot = n;
                        newNode = true;
                    }
                }
                else {
                    if (tmpRoot.right != null) {
                        tmpRoot = tmpRoot.right;
                    }
                    else {
                        tmpRoot.right = n;
                        n.parent = tmpRoot;
                        tmpRoot = n;
                        newNode = true;
                    }

                }
                if (i == 31) {
                    if (!newNode) {
                        tmpRoot.increase();
                    }
                }
            }
        }


    }
}
