For an array b of length m we define the function f as 

 f(b) = \begin{cases} b[1] &   if  m = 1 \\\ f(b[1] ⊕ b[2],b[2] ⊕ b[3],...,b[m-1] ⊕ b[m]) &   otherwise, \end{cases}  

where ⊕ is [bitwise exclusive OR](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).

For example, f(1,2,4,8)=f(1⊕2,2⊕4,4⊕8)=f(3,6,12)=f(3⊕6,6⊕12)=f(5,10)=f(5⊕10)=f(15)=15

You are given an array a and a few queries. Each query is represented as two integers l and r. The answer is the maximum value of f on all continuous subsegments of the array a_l, a_{l+1}, …, a_r.

Input

The first line contains a single integer n (1 ≤ n ≤ 5000) — the length of a.

The second line contains n integers a_1, a_2, ..., a_n (0 ≤ a_i ≤ 2^{30}-1) — the elements of the array.

The third line contains a single integer q (1 ≤ q ≤ 100 000) — the number of queries.

Each of the next q lines contains a query represented as two integers l, r (1 ≤ l ≤ r ≤ n).

Output

Print q lines — the answers for the queries.

Examples

Input

3
8 4 1
2
2 3
1 2


Output

5
12


Input

6
1 2 4 8 16 32
4
1 6
2 5
3 4
1 2


Output

60
30
12
3

Note

In first sample in both queries the maximum value of the function is reached on the subsegment that is equal to the whole segment.

In second sample, optimal segment for first query are [3,6], for second query — [2,5], for third — [3,4], for fourth — [1,2].
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class D_2 {
    static int save[][], start[], max[], arr[];
    public static void main(String[] args) throws Exception {
        FastReader in = new FastReader(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = in.nextInt();
        save = new int[n+1][];
        start = new int[n+1];
        max = new int[n+1];

        for (int i = 1; i <= n; i++) {
            save[i] = new int[n-i+2];
            for(int k = 1, p = 1; k <= n-i+1; k++, p++){
                if(i == 1) save[i][p] = in.nextInt();
                else save[i][p] = save[i-1][p] ^ save[i-1][p+1];
            }
        }


        arr = new int[(n*(n+1))/2];
        for(int i = 1, p = 0; i <= n; i++){
            start[i] = p;
            for(int k = 1; k <= i; k++){
               int x = i - k + 1;
               max[k] = max(max[k], save[x][k]);
               arr[p++] = max[k];
            }
        }
        
        SegTree seg = new SegTree(arr.length);
        seg.build();

        int q = in.nextInt();
        for (int i = 0; i < q; i++) {
            int l = in.nextInt(), r = in.nextInt();
            int s = start[r] + l - 1, e = start[r] + r - 1;
            pw.println(seg.query(s+1, e+1));
        }


        pw.close();
    }

    static void debug(Object... obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    //static int arr[];
    static class SegTree{
        int n , seg[];
        SegTree(int N){
            n = N;
            seg = new int[37508500];
        }
        void build(){
            build(1, 1, n);
        }
        void build(int p, int s, int e){
            if(s == e){
                seg[p] = arr[s-1];
                return;
            }
            if(s > e ) return;
            int m = (s+e)/2, l = 2*p, r = 2*p+1;
            build(l, s, m); build(r, m+1, e);
            seg[p] = max(seg[l], seg[r]);
        }

        void update(int p, int s, int e, int pos, int val){
            if(s == pos && e == pos){
                seg[p] = arr[s] = val;
                return;
            }
            if(s > pos || s > e || e < pos) return;
            int m = (s+e)/2, l = 2*p, r = 2*p+1;
            update(l, s, m, pos, val);
            update(r, m+1, e, pos, val);
            seg[p] = max(seg[l], seg[r]);
        }

        int query(int l, int r){
            return query(1, 1, n, l, r);
        }

        int query(int p, int s, int e, int a, int b){
            if(s >= a && e <= b){
                return seg[p];
            }
            if(s > e || s > b || e < a) return 0;
            int m = (s+e)/2, l = 2*p, r = 2*p+1;
            return max(query(l, s, m, a, b), query(r, m+1,e , a, b));
        }
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;
        static final int ints[] = new int[128];

        public FastReader(InputStream is) {
            for (int i = '0'; i <= '9'; i++) ints[i] = i - '0';
            this.is = is;
        }

        public int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }

        public String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + ints[b];
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + ints[b];
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
       /* public char nextChar() {
            return (char)skip();
        }*/

        public char[] next(int n) {
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }

        /*private char buff[] = new char[1005];
        public char[] nextCharArray(){
            int b = skip(), p = 0;
            while(!(isSpaceChar(b))){
                buff[p++] = (char)b;
                b = readByte();
            }
            return Arrays.copyOf(buff, p);
        }*/
    }
}