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 in = new InputReader(inputStream);
            PrintWriter out = new PrintWriter(outputStream);
            TaskE solver = new TaskE();
            solver.solve(1, in, out);
            out.flush();out.close();
        }
            static class TaskE {
              int f[][];
              void upd(int id,int max,int v,int p){
               while(p<=max){
                f[id][p]=Math.max(f[id][p],v);p+=p&-p;
               }
              }
              int get(int id,int p){
               int ans=-1;
               while(p>0){
                ans=Math.max(ans,f[id][p]);p-=p&-p;
               }return ans;
              }
              class pair{
               int l,r,id;pair(int a,int b,int c){l=a;r=b;id=c;}
              }
              public void solve(int testNumber, InputReader in, PrintWriter out) {
                  int n=in.nextInt();
                  int a[]=new int[n];
                  f=new int[n][n+1];
                  for(int i=0;i<n;i++)Arrays.fill(f[i],-1);
                  for(int i=0;i<n;i++)a[i]=in.nextInt();
                  int pre[][]=new int[n+1][2];int t=0;
                  for(int i=0;i<n;i++){
                   pre[0][t]=a[i];upd(i,n,pre[0][t],i+1);
                   for(int j=1;j<=i;j++){
                    pre[j][t]=pre[j-1][t^1]^pre[j-1][t];
                    upd(i-j,n,pre[j][t],i+1);
                   }t^=1;
                  }
                  int q=in.nextInt();
                  ArrayList<pair> al=new ArrayList<>();
                  for(int i=1;i<=q;i++){
                   al.add(new pair(in.nextInt()-1,in.nextInt()-1,i));
                  }Collections.sort(al,new Comparator<pair>(){
                   public int compare(pair p1,pair p2){
                    if(p1.r==p2.r)return p2.l-p1.l;
                    return p1.r-p2.r;
                   }
                  });
                  int pvt=-1,ans=-1,pt=-1;
                  int qa[]=new int[q+1];
                  //System.out.println("Hi");
                  for(int i=0;i<q;i++){
                   int r=al.get(i).r,l=al.get(i).l;
                   if(r!=pvt){
                    ans=-1;pvt=r;pt=r;
                   }
                    for(int j=pt;j>=l;j--){
                     ans=Math.max(ans,get(j,r+1));
                    }
                    pt=l-1;
                    qa[al.get(i).id]=ans;
                  }
                  for(int i=1;i<=q;i++)out.println(qa[i]);
              }
              /*
4
              1 2 3 4
              10
              1 1
              1 2
              1 3
              1 4
              2 2
              2 3
              2 4
              3 3
              3 4
              4 4
              */
//              int ja[][],from[],to[],c[];
//              void make(int n,int m,InputReader in){
//               ja=new int[n+1][];from=new int[m];to=new int[m];c=new int[n+1];
//               for(int i=0;i<m;i++){
//                from[i]=in.nextInt();to[i]=in.nextInt();
//                c[from[i]]++;c[to[i]]++;
//               }
//               for(int i=1;i<=n;i++){
//                ja[i]=new int[c[i]];c[i]=0;
//               }
//               for(int i=0;i<m;i++){
//                ja[from[i]][c[from[i]]++]=to[i];
//                ja[to[i]][c[to[i]]++]=from[i];
//               }
//              }
              
    //        pair[] radixSort(pair[] f){ return radixSort(f, f.length); }
    //	pair[] radixSort(pair[] f, int n)
    //	{
    //		pair[] to = new pair[n];
    //		{
    //			int[] b = new int[65537];
    //			for(int i = 0;i < n;i++)b[1+(f[i].v&0xffff)]++;
    //			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
    //			for(int i = 0;i < n;i++){
    //                         to[b[f[i].v&0xffff]++] = f[i];
    //                        }
    //			pair[] d = f; f = to;to = d;
    //		}
    //		{
    //			int[] b = new int[65537];
    //			for(int i = 0;i < n;i++)b[1+(f[i].v>>>16)]++;
    //			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
    //			for(int i = 0;i < n;i++)to[b[f[i].v>>>16]++] = f[i];
    //			pair[] d = f; f = to;to = d;
    //		}
    //		return f;
    //	}
           }
        static class InputReader {
            BufferedReader br;
            StringTokenizer st;
            public InputReader(InputStream stream) {
                br = new BufferedReader(new InputStreamReader(stream));
                st = null;
            }

            String next() {
                while (st == null || !st.hasMoreTokens()) {
                    String s = null;
                    try {
                        s = br.readLine();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    if (s == null)
                        return null;
                    st = new StringTokenizer(s);
                }
                return st.nextToken();
            }

            boolean hasMoreTokens() {
                while (st == null || !st.hasMoreTokens()) {
                    String s = null;
                    try {
                        s = br.readLine();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    if (s == null)
                        return false;
                    st = new StringTokenizer(s);
                }
                return true;
            }

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