#include <bits/stdc++.h>
using namespace std;
const int N = 5120;
int n, q, l, r, a[N], f[N][N], dp[N][N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = n; i >= 1; i--)
    for (int j = i; j <= n; j++)
      f[i][j] = i == j ? a[i] : f[i][j - 1] ^ f[i + 1][j],
      dp[i][j] = max(max(dp[i][j - 1], dp[i + 1][j]), f[i][j]);
  for (cin >> q; q--;) scanf("%d%d", &l, &r), printf("%d\n", dp[l][r]);
}
