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