#include <bits/stdc++.h>
using namespace std;
const int maxn = 5000 + 5;
int dp[maxn][maxn], a[maxn][maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n, q;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i][i];
    dp[i][i] = a[i][i];
  }
  for (int l = 1; l < n; l++) {
    for (int i = 0; i + l < n; i++) {
      int j = i + l;
      a[i][j] = a[i][j - 1] ^ a[i + 1][j];
    }
  }
  for (int l = 1; l < n; l++) {
    for (int i = 0; i + l < n; i++) {
      int j = i + l;
      dp[i][j] = max(dp[i][j - 1], dp[i + 1][j]);
      dp[i][j] = max(dp[i][j], a[i][j]);
    }
  }
  cin >> q;
  while (q--) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    cout << dp[u][v] << endl;
  }
}
