#include <bits/stdc++.h>
using namespace std;
const int N = 5000 + 5;
int n, a[N];
int f[N][N];
int g[N][N];
void calc(int l, int r) {
  if (l == r) return;
  for (int i = l; i < r; i++) {
    a[i] = a[i] ^ a[i + 1];
    f[i][n - r + 2] = a[i];
  }
  calc(l, r - 1);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) f[i][1] = g[i][1] = a[i];
  calc(1, n);
  for (int i = n; i >= 1; i--)
    for (int j = 1; j <= n; j++)
      if (i + j - 1 <= n) {
        g[i][j] = max(f[i][j], max(g[i][j - 1], g[i + 1][j - 1]));
      }
  int m, l, r;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &l, &r);
    printf("%d\n", g[l][r - l + 1]);
  }
  return 0;
}
