#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long nm = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) nm = nm * 10 + c - '0';
  return nm * f;
}
int dp[5010][5010], ans[5010][5010];
int main() {
  int n = read();
  for (int i = 1; i <= n; i++) ans[i][i] = dp[i][i] = read();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j + i <= n; j++) {
      int l = j, r = j + i;
      dp[l][r] = dp[l][r - 1] ^ dp[l + 1][r];
      ans[l][r] = max(ans[l][r - 1], max(ans[l + 1][r], dp[l][r]));
    }
  }
  int q = read();
  while (q--) {
    int l = read(), r = read();
    cout << ans[l][r] << "\n";
  }
  return 0;
}
