#include <bits/stdc++.h>
using namespace std;
int f[5007][5007], ans[5007][5007], n, q, l, r, i;
int main() {
  for (scanf("%d", &n), i = 1; i <= n; i++)
    scanf("%d", f[i] + i), ans[i][i] = f[i][i];
  for (int len = 2; len <= n; len++)
    for (l = 1, r; (r = l + len - 1) <= n; l++) {
      f[l][r] = f[l][r - 1] ^ f[l + 1][r];
      ans[l][r] = std::max(f[l][r], std::max(ans[l][r - 1], ans[l + 1][r]));
    }
  for (scanf("%d", &q), i = 0; i < q; i++) {
    scanf("%d%d", &l, &r);
    printf("%d\n", ans[l][r]);
  }
  return 0;
}
