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