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