#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-6;
const int N = 5005;
int dp[N][N], ans[N][N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &dp[i][1]), ans[i][1] = dp[i][1];
  for (int j = 2; j <= n; j++) {
    for (int i = 1; i + j - 1 <= n; i++) {
      dp[i][j] = dp[i][j - 1] ^ dp[i + 1][j - 1];
      ans[i][j] = max(dp[i][j], max(ans[i + 1][j - 1], ans[i][j - 1]));
    }
  }
  for (int i = 1; i <= n; i++) ans[i][1] = dp[i][1];
  int q;
  scanf("%d", &q);
  while (q--) {
    static int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", ans[l][r - l + 1]);
  }
  return 0;
}
