#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int dp[N][N];
int a[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    dp[0][i] = a[i];
  }
  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;
  int l, r;
  while (q--) {
    cin >> l >> r;
    cout << (dp[r - l][l - 1]) << endl;
  }
  return 0;
}
