#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int memo[5000][5000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int &e : a) cin >> e;
  for (int i = 0; i < n; i++) memo[i][i] = a[i];
  for (int i = 1; i < n; i++)
    for (int j = 0; j + i < n; j++) {
      memo[j][i + j] = max(memo[j][i + j - 1], memo[j + 1][i + j]);
      memo[j][i + j] = max(memo[j][i + j], a[j] ^ a[j + 1]);
      a[j] ^= a[j + 1];
    }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << memo[l - 1][r - 1] << "\n";
  }
  cin >> n;
}
