#include <bits/stdc++.h>
using namespace std;
const int infinity = 2000000999 / 2;
const long long int inff = 4000000000000000999;
template <class T>
T get() {
  T a;
  cin >> a;
  return a;
}
template <class T, class U>
ostream& operator<<(ostream& out, const pair<T, U>& par) {
  out << "[" << par.first << ";" << par.second << "]";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const set<T>& cont) {
  out << "{";
  for (const auto& x : cont) out << x << ", ";
  out << "}";
  return out;
}
template <class T, class U>
ostream& operator<<(ostream& out, const map<T, U>& cont) {
  out << "{";
  for (const auto& x : cont) out << x << ", ";
  out << "}";
  return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  for (int i = 0; i < (int)v.size(); i++) {
    if (i) out << " ";
    out << v[i];
  }
  out << endl;
  return out;
}
bool ccw(complex<long double> p, complex<long double> a,
         complex<long double> b) {
  if ((conj(a - p) * (b - p)).imag() <= 0)
    return (0);
  else
    return (1);
}
int main() {
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  int n = get<int>();
  vector<int> A;
  for (int i = 0; i < (int)n; i++) A.push_back(get<int>());
  vector<vector<int> > H(n, vector<int>(n, 0));
  for (int i = 0; i < (int)n; i++) H[i][0] = A[i];
  for (int j = 1; j < n; j++) {
    for (int i = 0; i + j < n; i++) {
      H[i][j] = H[i][j - 1] ^ H[i + 1][j - 1];
    }
  }
  if (0) cout << "H:\n " << H;
  vector<vector<int> > res(n, vector<int>(n + 1, 0));
  for (int i = 0; i < (int)n; i++) res[i][i + 1] = H[i][0];
  for (int j = 0; j < (int)n + 1; j++) {
    for (int i = j - 1; i >= 0; i--) {
      if (0)
        cout << "res for [" << i << "][" << j << "] = max(" << H[i][j - i - 1]
             << ", " << (i != j - 1 ? res[i + 1][j] : -1) << ", "
             << (j ? res[i][j - 1] : -1) << endl;
      res[i][j] = max(H[i][j - i - 1], max((i != j - 1 ? res[i + 1][j] : 0),
                                           (j ? res[i][j - 1] : 0)));
    }
  }
  if (0) cout << "res:\n " << res;
  int q = get<int>();
  for (int i = 0; i < (int)q; i++) {
    int l = get<int>() - 1;
    int r = get<int>();
    cout << res[l][r] << "\n";
  }
}
