#include <bits/stdc++.h>
using namespace std;
int a[5005], g[5005][5005], ans[5005][5005], n, Q, ll, rr;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), g[i][i] = ans[i][i] = a[i];
  for (int i = 2; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (j + i - 1 <= n && j + 1 <= n)
        g[j][j + i - 1] = g[j][j + i - 2] ^ g[j + 1][j + i - 1];
  for (int i = 2; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (j + i - 1 <= n && j + 1 <= n)
        ans[j][j + i - 1] =
            max(ans[j][j + i - 2], max(ans[j + 1][j + i - 1], g[j][i + j - 1]));
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d", &ll, &rr);
    printf("%d\n", ans[ll][rr]);
  }
  return 0;
}
