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