#include <bits/stdc++.h>
using namespace std;
int f[5001][5001];
int main() {
  int n, x, y, m;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> f[i][i];
  }
  for (int g = n; g; --g) {
    for (int h = g + 1; h <= n; ++h) {
      f[g][h] = (f[g][h - 1] ^ f[g + 1][h]);
    }
  }
  for (int g = n; g; --g) {
    for (int h = g + 1; h <= n; ++h) {
      f[g][h] = max(f[g][h], max(f[g][h - 1], f[g + 1][h]));
    }
  }
  cin >> m;
  while (m--) {
    cin >> x >> y;
    cout << f[x][y] << endl;
  }
  return 0;
}
