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