#include <bits/stdc++.h>
using namespace std;
int a[5000 + 5];
int xo[5000 + 5][5000 + 5], dp[5000 + 5][5000 + 5];
int semnificativ(int k) {
  int ans = k;
  while (k != 0) {
    ans = k;
    k = k & (k - 1);
  }
  return ans;
}
int main() {
  int n, i, k, j, semn, q, l, r;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (i = 1; i <= n; i++) {
    xo[i][1] = a[i];
  }
  for (k = 2; k <= n; k++) {
    for (i = 1; i + k <= n + 1; i++) {
      semn = semnificativ(k);
      if (semn == k) semn /= 2;
      xo[i][k] = (xo[i][k - semn] ^ xo[i + semn][k - semn]);
    }
  }
  for (k = 0; k <= n + 1; k++)
    for (i = 1; i + k <= n + 2; i++) {
      j = i + k;
      dp[i][j] = max(dp[i + 1][j], dp[i][j - 1]);
      dp[i][j] = max(dp[i][j], xo[i][j - i + 1]);
    }
  cin >> q;
  while (q--) {
    cin >> l >> r;
    cout << dp[l][r] << '\n';
  }
  return 0;
}
