#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e3 + 10;
int n, a[MAX], dp[MAX][MAX], tmp[MAX], nxt[MAX];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int k = 1; k <= n; k++) {
    for (int i = 0; i + k <= n; i++) {
      int j = i + k;
      if (k == 1) {
        nxt[i] = a[i];
        dp[i][j] = nxt[i];
        continue;
      }
      dp[i][j] = max(dp[i][j - 1], dp[i + 1][j]);
      nxt[i] = tmp[i] ^ tmp[i + 1];
      dp[i][j] = max(dp[i][j], nxt[i]);
    }
    for (int i = 0; i < n; i++) tmp[i] = nxt[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    l--;
    cout << dp[l][r] << '\n';
  }
  return 0;
}
