#include <bits/stdc++.h>
using namespace std;
int f[5010][5010], ans[5010][5010];
int v[5010];
int n, m;
void init() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &v[i]), f[i][1] = v[i], ans[i][1] = v[i];
  for (int len = 2; len <= n; len++)
    for (int pos = 1; pos <= n - len + 1; pos++)
      f[pos][len] = f[pos][len - 1] ^ f[pos + 1][len - 1];
  for (int len = 2; len <= n; len++)
    for (int pos = 1; pos <= n - len + 1; pos++)
      ans[pos][len] =
          max(f[pos][len], max(ans[pos][len - 1], ans[pos + 1][len - 1]));
}
void query() {
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    printf("%d\n", ans[l][r - l + 1]);
  }
}
int main() {
  init();
  query();
}
