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