#include <bits/stdc++.h>
using namespace std;
int const MAX = 5e3 + 41;
int d[MAX][MAX];
int a[MAX];
int const Q = 1e5 + 41;
int n;
int q;
int l[Q];
int r[Q];
int d1[MAX][MAX];
int rec2(int l, int r) {
  if (l == r) {
    return a[l];
  }
  if (d1[l][r] != -1) return d1[l][r];
  int res = rec2(l + 1, r) ^ rec2(l, r - 1);
  d1[l][r] = res;
  return res;
}
int rec1(int l, int r) {
  if (l == r) {
    return a[l];
  }
  if (d[l][r] != -1) return d[l][r];
  int res = max(rec1(l + 1, r), rec1(l, r - 1));
  res = max(res, rec2(l, r));
  d[l][r] = res;
  return res;
}
void solve() {
  memset(d, 255, sizeof(d));
  memset(d1, 255, sizeof(d1));
  for (int i = 1; i <= q; i++) {
    int resp = rec1(l[i], r[i]);
    printf("%d\n", resp);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &l[i], &r[i]);
  }
  solve();
  return 0;
}
