#include <bits/stdc++.h>
using namespace std;
int a[5000], b[5000][5000], dp[5000][5000];
int solve2(int i, int j) {
  if (b[i][j] != -1) return b[i][j];
  if (i == j) {
    dp[i][j] = a[i];
    return dp[i][j];
  }
  b[i][j] = solve2(i, j - 1) ^ solve2(i + 1, j);
  return b[i][j];
}
int solve(int i, int j) {
  if (dp[i][j] != -1) return dp[i][j];
  if (i == j) {
    dp[i][j] = a[i];
    return dp[i][j];
  }
  dp[i][j] = max(max(solve(i + 1, j), solve(i, j - 1)), b[i][j]);
  return dp[i][j];
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, i, j, l, r, q, temp;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  memset(b, -1, sizeof(b));
  memset(dp, -1, sizeof(dp));
  temp = solve2(0, n - 1);
  temp = solve(0, n - 1);
  cin >> q;
  while (q--) {
    cin >> l >> r;
    cout << dp[l - 1][r - 1];
    cout << endl;
  }
  return 0;
}
