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

public class C implements Runnable {

    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer tok = new StringTokenizer("");

    private void init() throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        String fileName = "";
        if (ONLINE_JUDGE && fileName.isEmpty()) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            try {
                if (fileName.isEmpty()) {
                    in = new BufferedReader(new FileReader("input.txt"));
                    out = new PrintWriter("output.txt");
                } else {
                    in = new BufferedReader(new FileReader(fileName + ".in"));
                    out = new PrintWriter(fileName + ".out");
                }
            } catch (Throwable t) {
                in = new BufferedReader(new InputStreamReader(System.in));
                out = new PrintWriter(System.out);
            }
        }
    }

    String readString() {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() {
        return Integer.parseInt(readString());
    }

    long readLong() {
        return Long.parseLong(readString());
    }

    double readDouble() {
        return Double.parseDouble(readString());
    }

    int[] readIntArray(int size) {
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = readInt();
        }
        return a;
    }

    public static void main(String[] args) {
        //new Thread(null, new _Solution(), "", 128 * (1L << 20)).start();
        new C().run();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    @Override
    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            init();
            solve();
            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    class Trie {
        final int level, bit;
        Trie zero, one;

        Trie(int level, int bit) {
            this.level = level;
            this.bit = bit;
        }

        void build(int x) {
            if (level == 0) return;
            int nextBit = Integer.bitCount(x & (1 << (level - 1)));
            if (nextBit == 0) {
                if (zero == null) zero = new Trie(level - 1, 0);
                zero.build(x);
            } else {
                if (one == null) one = new Trie(level - 1, 0);
                one.build(x);
            }
        }

        boolean delete(int x) {
            if (level == 0) return true;
            int nextBit = Integer.bitCount(x & (1 << (level - 1)));
            if (nextBit == 0) {
                if (zero.delete(x)) zero = null;
            } else {
                if (one.delete(x)) one = null;
            }
            return zero == null && one == null;
        }

        int maxXor(int x, int curNumber) {
            if (level == 0) return curNumber ^ x;
            int nextBit = Integer.bitCount(x & (1 << (level - 1)));
            if (nextBit == 0) {
                if (one == null) {
                    return zero.maxXor(x, curNumber);
                } else {
                    return one.maxXor(x, curNumber | (1 << (level - 1)));
                }
            } else {
                if (zero == null) {
                    return one.maxXor(x, curNumber | (1 << (level - 1)));
                } else {
                    return zero.maxXor(x, curNumber);
                }
            }
        }
    }

    class Stupid {
        List<Integer> list = new ArrayList<>();

        void add(int x) {
            list.add(x);
        }

        void remove(int x) {
            list.remove((Integer) x);
        }

        int maxXor(int x) {
            int ans = x;
            for (int t : list) {
                ans = Math.max(ans, t ^ x);
            }
            return ans;
        }
    }

    void solve() throws IOException {
        Trie root = new Trie(31, 0);
        root.build(0);
        int q = readInt();
        Map<Integer, Integer> count = new HashMap<>();

       // Stupid stupid = new Stupid();

        while (q-- > 0) {
            char c = readString().toCharArray()[0];
            if (c == '+') {
                int x = readInt();
                Integer curCount = count.get(x);
                if (curCount == null || curCount == 0) {
                    root.build(x);
                   // stupid.add(x);
                    curCount = 0;
                }
                count.put(x, curCount + 1);
            }
            if (c == '-') {
                int x = readInt();
                Integer curCount = count.get(x);
                if (curCount == null) continue;
                if (curCount == 1) {
                    root.delete(x);
                   // stupid.remove(x);
                }
                count.put(x, curCount - 1);
            }
            if (c == '?') {
                int x = readInt();
                int my = root.maxXor(x, 0);
               // int others = stupid.maxXor(x);
//                if (my != others) {
//                    System.err.println("FIRE YOUR ASS");
//                }
                out.println(my);
            }
        }
    }
}
