#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 10;
int dp[maxn][maxn], l, r, q, n, maxx[maxn][maxn];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &dp[i][i]);
    maxx[i][i] = dp[i][i];
  }
  for (int len = 2; len <= n; len++)
    for (int i = 1; i <= n - len + 1; i++) {
      int j = i + len - 1;
      dp[i][j] = dp[i][j - 1] ^ dp[i + 1][j];
      maxx[i][j] = max(maxx[i][j - 1], maxx[i + 1][j]);
      maxx[i][j] = max(maxx[i][j], dp[i][j]);
    }
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &l, &r);
    printf("%d\n", maxx[l][r]);
  }
  return 0;
}
