#include <bits/stdc++.h>
using namespace std;
int mx(int a, int b, int c) { return max(max(a, b), c); }
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int dp[n + 1][n + 1];
  int ans[n + 1][n + 1];
  memset(dp, -1, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    dp[i][i] = a[i - 1];
    ans[i][i] = a[i - 1];
  }
  for (int l = 1; l < n; l++) {
    for (int j = 1; j <= n - l; j++) {
      dp[j][j + l] = dp[j + 1][j + l] ^ dp[j][j + l - 1];
      ans[j][j + l] = mx(dp[j][j + l], ans[j + 1][j + l], ans[j][j + l - 1]);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << ans[l][r] << endl;
  }
}
