#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5192;
int dp[MAXN][MAXN][2];
int n, q;
int a[MAXN];
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cerr << "HELLO WORLD :)\n";
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int j = 1; j <= n; j++) {
    for (int l = 0; l + j - 1 < n; l++) {
      int r = l + j - 1;
      if (j == 1) {
        dp[l][r][0] = a[l];
        dp[l][r][1] = dp[l][r][0];
        continue;
      }
      dp[l][r][0] = dp[l + 1][r][0] ^ dp[l][r - 1][0];
      dp[l][r][1] = max({dp[l + 1][r][1], dp[l][r - 1][1], dp[l][r][0]});
    }
  }
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    cout << dp[l][r][1] << '\n';
  }
  return false;
}
