#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
const int oo = 1000000007;
int n, a[N], sa[N], f[N][N], g[N][N], mg[N][N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  vector<int> v;
  for (int i = n; i >= 1; --i) {
    for (int j = i; j <= n; ++j) {
      if (i == j) {
        f[i][j] = a[i];
        continue;
      }
      f[i][j] = f[i][j - 1] ^ f[i + 1][j];
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = i; j <= n; ++j) g[i][j] = max(g[i][j - 1], f[i][j]);
  for (int r = 1; r <= n; ++r)
    for (int l = r; l >= 1; --l) mg[l][r] = max(mg[l + 1][r], g[l][r]);
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", mg[l][r]);
  }
}
