#include <bits/stdc++.h>
using namespace std;
int n, Q, f[5003][5003], ans[5003][5003];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &f[i][i]);
  for (int l = 2; l <= n; l++)
    for (int i = 1; i + l - 1 <= n; i++)
      f[i][i + l - 1] = f[i][i + l - 2] ^ f[i + 1][i + l - 1];
  for (int i = 1; i <= n; i++) ans[i][i] = f[i][i];
  for (int l = 2; l <= n; l++)
    for (int i = 1; i + l - 1 <= n; i++)
      ans[i][i + l - 1] =
          max(f[i][i + l - 1], max(ans[i][i + l - 2], ans[i + 1][i + l - 1]));
  scanf("%d", &Q);
  while (Q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    printf("%d\n", ans[x][y]);
  }
}
