#include <bits/stdc++.h>
using namespace std;
struct str {
  int x, y, w;
  bool operator<(const str& A) const { return w < A.w; }
};
int arr[5001];
int pre[5001][5001];
int dp[5001][5001];
int n, m, k, lv, q;
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    pre[lv][i] = arr[i];
  }
  for (int i = n - 1; i >= 1; i--) {
    ++lv;
    for (int j = 0; j < i; j++) {
      pre[lv][j] = pre[lv - 1][j] ^ pre[lv - 1][j + 1];
    }
  }
  for (int i = 0; i < n; i++) dp[i][i] = arr[i];
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < n - i; j++) {
      dp[j][j + i] = max(dp[j + 1][j + i], max(dp[j][j + i - 1], pre[i][j]));
    }
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    --l;
    --r;
    printf("%d\n", dp[l][r]);
  }
  return 0;
}
