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