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.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        ConsoleIO io = new ConsoleIO();
        new Main(io).solve();
        io.close();
    }

    ConsoleIO io;

    Main(ConsoleIO io) {
        this.io = io;
    }

    ArrayList<ArrayList<Edge>> gr;

    class Edge {
        public Edge(int uu, int vv, int ii) {
            u = uu;
            v = vv;
            i = ii;
        }

        public int u;
        public int v;
        public int i;
    }

    long MOD = 1_000_000_007;
    int N, M;
    int[] ccc;
    int[] cur;
    boolean[] visit;

    class Node{
        public int count;
        public Node ch0;
        public Node ch1;
        public int shift;
    }
    Node root;
    public void solve() {
        N = Integer.parseInt(io.readLine());

        root = new Node();
        root.count = 1;
        root.shift = 30;
        Node cur = root;
        for(int i = 0;i<30;i++) {
            Node x = new Node();
            x.count = 1;
            x.shift = 29 - i;
            cur.ch0 = x;
            cur = x;
        }

        StringBuilder res = new StringBuilder();
        for(int i = 0;i<N;i++){
            String s = io.readLine().trim();
            int v = Integer.parseInt(s.substring(2));
            if(s.charAt(0) == '+'){
                change(v, 1);
            }
            else if(s.charAt(0) == '-'){
                change(v,-1);
            } else{
                int r = calc(v);
                if(res.length()>0)res.append(System.lineSeparator());
                res.append(r);
            }
        }
        io.writeLine(res.toString());
    }

    void change(int v, int dif) {
        Node cur = root;
        int sh = 29;
        while (sh >= 0) {
            int z = (v >> sh) & 1;
            Node next;
            if (z == 0) {
                next = cur.ch0;
            } else {
                next = cur.ch1;
            }

            if (next == null) {
                next = new Node();
                next.shift = sh;
                if (z == 0) cur.ch0 = next;
                else cur.ch1 = next;
            }

            next.count += dif;

            cur = next;
            sh--;
        }
    }

    int calc(int v) {
        Node cur = root;
        int sh = 29;
        int res = 0;
        while (sh >= 0) {
            int z = (v >> sh) & 1;

            Node next;
            if (z == 0) {
                if (cur.ch1 == null || cur.ch1.count == 0) next = cur.ch0;
                else {
                    next = cur.ch1;
                    res |= 1 << cur.ch1.shift;
                }
            } else {
                if (cur.ch0 == null || cur.ch0.count == 0) next = cur.ch1;
                else {
                    next = cur.ch0;
                    res |= 1 << cur.ch0.shift;
                }
            }

            cur = next;
            sh--;
        }

        return res;
    }
}

class ConsoleIO {
    BufferedReader br;
    PrintWriter out;
    public ConsoleIO(){br = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);}
    public void flush(){this.out.flush();}
    public void close(){this.out.close();}
    public void writeLine(String s) {this.out.println(s);}
    public void writeInt(int a) {this.out.print(a);this.out.print(' ');}
    public void writeWord(String s){
        this.out.print(s);
    }
    public void writeIntArray(int[] a, int k, String separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < k; i++) {
            if (i > 0) sb.append(separator);
            sb.append(a[i]);
        }
        this.writeLine(sb.toString());
    }
    public int read(char[] buf, int len){try {return br.read(buf,0,len);}catch (Exception ex){ return -1; }}
    public String readLine() {try {return br.readLine();}catch (Exception ex){ return "";}}
    public long[] readLongArray() {
        String[]n=this.readLine().trim().split("\\s+");long[]r=new long[n.length];
        for(int i=0;i<n.length;i++)r[i]=Long.parseLong(n[i]);
        return r;
    }
    public int[] readIntArray() {
        String[]n=this.readLine().trim().split("\\s+");int[]r=new int[n.length];
        for(int i=0;i<n.length;i++)r[i]=Integer.parseInt(n[i]);
        return r;
    }
    public int[] readIntArray(int n) {
        int[] res = new int[n];
        char[] all = this.readLine().toCharArray();
        int cur = 0;boolean have = false;
        int k = 0;
        boolean neg = false;
        for(int i = 0;i<all.length;i++){
            if(all[i]>='0' && all[i]<='9'){
                cur = cur*10+all[i]-'0';
                have = true;
            }else if(all[i]=='-') {
                neg = true;
            }
            else if(have){
                res[k++] = neg?-cur:cur;
                cur = 0;
                have = false;
                neg = false;
            }
        }
        if(have)res[k++] = neg?-cur:cur;
        return res;
    }
    public int readInt() {
        try {
            int r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public long readLong() {
        try {
            long r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public String readWord() {
        try {
            boolean start = false;
            StringBuilder sb = new StringBuilder();
            while (true) {
                int c = br.read();
                if (c!= ' ' && c!= '\r' && c!='\n' && c!='\t') {
                    sb.append((char)c);
                    start = true;
                } else if (start || c == -1) return sb.toString();
            }
        } catch (Exception ex) {
            return "";
        }
    }
}
class Pair {
    public Pair(int a, int b) {this.a = a;this.b = b;}
    public int a;
    public int b;
}
class Tri {
    public Tri(int a, int b, int c) {this.a = a;this.b = b;this.c = c;}
    public int a;
    public int b;
    public int c;
}
class PairLL {
    public PairLL(long a, long b) {this.a = a;this.b = b;}
    public long a;
    public long b;
}




