#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
long long fix_mod(long long x, long long y) { return (y + x % y) % y; }
void fast() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
long long mem[5006][5006];
int main() {
  fast();
  int n;
  cin >> n;
  vector<long long> v(n + 1, 0);
  for (int i = 1; i <= n; i++) cin >> v[i], mem[1][i] = v[i];
  for (int j = 2; j <= n; j++) {
    for (int i = 1; i + j - 1 <= n; i++) {
      v[i] ^= v[i + 1];
      mem[j][i] = v[i];
    }
  }
  for (int j = 1; j <= n; j++) {
    for (int i = 1; i + j - 1 <= n; i++) {
      mem[j][i] = max(mem[j - 1][i], mem[j][i]);
      mem[j][i] = max(mem[j - 1][i + 1], mem[j][i]);
    }
  }
  int q, l, r;
  cin >> q;
  while (q--) {
    cin >> l >> r;
    cout << mem[r - l + 1][l] << "\n";
  }
}
