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