#include <bits/stdc++.h>
using namespace std;
int f[5010][5010], ans[5010][5010];
int n, q;
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 = 1; i < n; i++)
    for (int j = 1; j <= n - i + 1; j++)
      f[j][j + i] = f[j][j + i - 1] ^ f[j + 1][j + i],
               ans[j][j + i] =
                   max(f[j][j + i], max(ans[j][j + i - 1], ans[j + 1][j + i]));
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", ans[l][r]);
  }
}
