#include <bits/stdc++.h>
using namespace std;
int n, a[5010], q, l, r, f[5010][5010], maxx[5010][5010];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &f[i][0]);
    maxx[i][0] = f[i][0];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n - i; j++) {
      f[j][i] = f[j][i - 1] ^ f[j + 1][i - 1];
      maxx[j][i] = max(f[j][i], max(maxx[j][i - 1], maxx[j + 1][i - 1]));
    }
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &l, &r);
    cout << maxx[l][r - l] << endl;
  }
  return 0;
}
