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.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Alex
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }
    static class TaskD {
        int BITS = 30;
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            Set set = new Set();
            int queries = in.readInt();
            for (int query = 0; query < queries; query++) {
                char type = in.readCharacter();
                int val = in.readInt();
                if (type == '+') {
                    set.add(val);
                } else if (type == '-') {
                    set.remove(val);
                } else if (type == '?') {
                    int ans = set.query(val);
                    out.printLine(ans);
                } else throw new RuntimeException();
            }
        }
        class Set {
            Node root = new Node(-1111);
            public Set() {
                add(0);
            }
            void add(int val) {
                Node cur = root;
                for (int bitidx = BITS - 1; bitidx >= 0; bitidx--) {
                    int bitval = (((val >> bitidx) & 1) == 0) ? 0 : 1;
                    if (cur.nxtNodes[bitval] == null) {
                        cur.nxtNodes[bitval] = new Node(bitval);
                    }
                    cur = cur.nxtNodes[bitval];
                    cur.count++;
                }
            }
            void remove(int val) {
                Node cur = root;
                for (int bitidx = BITS - 1; bitidx >= 0; bitidx--) {
                    int bitval = (((val >> bitidx) & 1) == 0) ? 0 : 1;
                    Node nxt = cur.nxtNodes[bitval];
                    nxt.count--;
                    if (nxt.count == 0) {
                        cur.nxtNodes[bitval] = null;
                        break;
                    }
                    cur = nxt;
                }
            }
            int query(int val) {
                Node cur = root;
                int ans = 0;
                for (int bitidx = BITS - 1; bitidx >= 0; bitidx--) {
                    int bitval = (((val >> bitidx) & 1) == 0) ? 0 : 1;
                    int wantbit = bitval ^ 1;
                    if (cur.nxtNodes[wantbit] != null) {
                        ans += (1 << bitidx);
                        cur = cur.nxtNodes[wantbit];
                    } else {
                        cur = cur.nxtNodes[bitval];
                    }
                }
                return ans;
            }
            class Node {
                int val;
                int count = 0;
                Node[] nxtNodes = new Node[2];
                public Node(int val) {
                    this.val = val;
                }
            }
        }
    }
    static class OutputWriter {
        private final PrintWriter writer;
        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }
        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }
        public void close() {
            writer.close();
        }
        public void printLine(int i) {
            writer.println(i);
        }
    }
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;
        public InputReader(InputStream stream) {
            this.stream = stream;
        }
        public 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++];
        }
        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return isWhitespace(c);
        }
        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
        public char readCharacter() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            return (char) c;
        }
        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

