#include <bits/stdc++.h>
using namespace std;
const int Maxn = 5000;
int N, A[Maxn + 5];
int f[Maxn + 5][Maxn + 5];
int ans[Maxn + 5][Maxn + 5];
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    ans[i][i] = f[i][i] = A[i];
  }
  for (int i = 2; i <= N; i++)
    for (int j = 1; j <= N - i + 1; j++) {
      int k = j + i - 1;
      f[j][k] = f[j + 1][k] ^ f[j][k - 1];
      ans[j][k] = max(ans[j + 1][k], ans[j][k - 1]);
      if (f[j][k] > ans[j][k]) ans[j][k] = f[j][k];
    }
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", ans[l][r]);
  }
  return 0;
}
