#include <bits/stdc++.h>
using namespace std;
int dp[5010][5010];
int main() {
  int n, i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) scanf("%d", &dp[i][i]);
  for (i = 1; i <= n; i++)
    for (j = 1; j + i <= n; j++)
      dp[j][j + i] = dp[j][j + i - 1] ^ dp[j + 1][i + j];
  for (i = 1; i <= n; i++)
    for (j = 1; j + i <= n; j++)
      dp[j][j + i] = max(dp[j][j + i], max(dp[j][j + i - 1], dp[j + 1][i + j]));
  int t, x, y;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &x, &y);
    printf("%d\n", dp[x][y]);
  }
}
