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

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inp = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(inp, out);
        out.close();
    }

    static class Solver {
        private class Pair {
            int x, y;
            Pair() {

            }
            Pair(int x, int y) {
                this.x = x;
                this.y = y;
            }
        }
        private void solve(InputReader inp, PrintWriter out) {
            int n = inp.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = inp.nextInt();
            }

            int[][] f = new int[n][n];
            for (int i = 0; i < n; ++i) {
                f[0][i] = a[i];
            }
            for (int i = 1; i < n; ++i) {
                for (int j = 0; j < n - i; ++j) {
                    f[i][j] = f[i - 1][j] ^ f[i - 1][j + 1];
                }
            }

            int m = inp.nextInt();
            Pair[] query = new Pair[m];
            List<Integer>[] qlist = new ArrayList[n];
            for (int i = 0; i < n; ++i) {
                qlist[i] = new ArrayList<>();
            }
            for (int i = 0; i < m; ++i) {
                query[i] = new Pair();
                query[i].x = inp.nextInt() - 1;
                query[i].y = inp.nextInt() - 1;
                qlist[query[i].y].add(i);
            }

            int[] g = new int[n];
            int[] ans = new int[m];
            for (int i = 0; i < m; ++i) {
                ans[i] = 0;
            }
            for (int r = 0; r < n; ++r) {
                for (int l = 0; l <= r; ++l) {
                    g[l] = Math.max(g[l], f[r - l][l]);
                }
                for (int i = n - 2; i >= 0; --i) {
                    g[i] = Math.max(g[i], g[i + 1]);
                }
                for (int i: qlist[r]) {
                    int l = query[i].x;
                    ans[i] = g[l];
                }
            }

            for (int i = 0; i < m; ++i) {
                out.println(ans[i]);
            }
        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}