#include <bits/stdc++.h>
using namespace std;
int n, Q, l, r;
int a[5000], b[5000][5000], c[5000][5000];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) b[i][i] = c[i][i] = a[i];
  for (int L = 1; L < n; L++)
    for (int i = 1; i + L <= n; i++) {
      int j = i + L;
      b[i][j] = b[i + 1][j] ^ b[i][j - 1];
      c[i][j] = max(b[i][j], max(c[i + 1][j], c[i][j - 1]));
    }
  scanf("%d", &Q);
  while (Q--) {
    scanf("%d%d", &l, &r);
    printf("%d\n", c[l][r]);
  }
}
