#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 5;
int n, f[5005][5005], a[MAXN], dp[5005][5005], q;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), f[i][i] = dp[i][i] = a[i];
  for (int j = 2; j <= n; j++) {
    for (int i = j - 1; i >= 1; i--) {
      f[i][j] = f[i][j - 1] ^ f[i + 1][j];
      dp[i][j] = ((f[i][j]) > (dp[i][j - 1]) ? (f[i][j]) : (dp[i][j - 1])) >
                         (dp[i + 1][j])
                     ? ((f[i][j]) > (dp[i][j - 1]) ? (f[i][j]) : (dp[i][j - 1]))
                     : (dp[i + 1][j]);
    }
  }
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", dp[l][r]);
  }
  return 0;
}
