#include <bits/stdc++.h>
using namespace std;
int n, q;
int arr[5005];
int dp[5005][5005];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
    dp[i][i] = arr[i];
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[j][j + i] = dp[j][j + i - 1] ^ dp[j + 1][j + i];
    }
  }
  for (int i = 1; i < n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[j][j + i] = max({dp[j][j + i], dp[j][j + i - 1], dp[j + 1][j + i]});
    }
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", dp[a][b]);
  }
  return 0;
}
