#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
int n, q, a[N], ans[N][N], dp[N][N];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) ans[i][i] = dp[i][i] = a[i];
  for (int x = 2; x <= n; x++)
    for (int i = 1; i + x - 1 <= n; i++)
      ans[i][i + x - 1] = ans[i][i + x - 2] ^ ans[i + 1][i + x - 1];
  for (int x = 2; x <= n; x++)
    for (int i = 1; i + x - 1 <= n; i++)
      dp[i][i + x - 1] =
          max(dp[i + 1][i + x - 1], max(dp[i][i + x - 2], ans[i][i + x - 1]));
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", dp[l][r]);
  }
  return 0;
}
