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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D706 solver = new D706();
        solver.solve(1, in, out);
        out.close();
    }

    static class D706 {
        HashMap<Integer, Integer> multiset = new HashMap<>();
        TreeSet<Integer> set = new TreeSet<>();

        void add(int i) {
            if (!multiset.containsKey(i)) {
                multiset.put(i, 1);
            } else {
                multiset.put(i, multiset.get(i) + 1);
            }
            set.add(i);
        }

        void remove(int i) {
            int cur = multiset.get(i);
            if (cur == 1) {
                set.remove(i);
            }
            multiset.put(i, multiset.get(i) - 1);
        }

        int mxor(int x) {
            int best = 0;
            for (int i = 1 << 30; i > 0; i >>= 1) {
//            System.out.print(Integer.toBinaryString(best));
                // are we seeking a number with this bit on?
                if ((x & i) == 0) {
                    // the bit is off in the number, so we'd like it to be on
                    Integer seek = set.ceiling(best + i);
                    if (seek != null && seek < (best + 2 * i)) {
                        // we found a number with this bit on, and it is an improvement
                        best += i;
                    }
                } else {
                    // this bit is already on; XOR-ing with another would detract
                    Integer seek = set.lower(best + i);
                    if (seek != null && seek >= best) {
                        // there is a number with this bit off
                        // we're safe; don't do anything!
                    } else {
                        // we must include this bit; there is no better way
                        best += i;
                    }
                }
//            System.out.println(" --> " + Integer.toBinaryString(best));

            }
            Integer hi = set.ceiling(best);
            Integer lo = set.floor(best);
            int ret = x;
            if (hi != null)
                ret = Math.max(ret, x ^ hi);
            if (lo != null)
                ret = Math.max(ret, x ^ lo);
            return ret;
        }

        public void solve(int testNumber, FastScanner s, PrintWriter out) {
//        add(0);
            int Q = s.nextInt();
            for (int i = 0; i < Q; i++) {
                char cmd = s.next().charAt(0);
                switch (cmd) {
                    case '+':
                        add(s.nextInt());
                        break;
                    case '-':
                        remove(s.nextInt());
                        break;
                    case '?':
                        out.println(mxor(s.nextInt()));
                        break;
                }
            }
        }

    }

    static class FastScanner {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public FastScanner(InputStream stream) {
            this.stream = stream;
        }

        int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

    }
}

