#include <bits/stdc++.h>
using namespace std;
long long p, q, b;
int cal[5050][5050];
int d[5050][5050];
int a[5050];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int k = 1; k <= n; k++)
    for (int i = 1; i + k - 1 <= n; i++) {
      int j = i + k - 1;
      if (i == j)
        cal[i][j] = a[i];
      else
        cal[i][j] = (cal[i + 1][j] ^ cal[i][j - 1]);
    }
  for (int k = 1; k <= n; k++)
    for (int i = 1; i + k - 1 <= n; i++) {
      int j = i + k - 1;
      if (i == j)
        d[i][j] = a[i];
      else {
        d[i][j] = max(max(cal[i][j], d[i + 1][j]), d[i][j - 1]);
      }
    }
  int Q;
  scanf("%d", &Q);
  while (Q--) {
    int u, v;
    scanf("%d %d", &u, &v);
    printf("%d\n", d[u][v]);
  }
  return 0;
}
