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