#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& os, vector<T> a) {
  os << "( ";
  for (T& x : a) os << x << " ";
  os << ")\n";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> a) {
  os << "( ";
  for (T x : a) os << x << " ";
  os << ")\n";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T, T> a) {
  os << "(" << a.first << " " << a.second << ") ";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, complex<T> a) {
  os << "(r=" << a.real() << " i=" << a.imag() << ") ";
  return os;
}
const int nmax = 5005;
int n, q, a[nmax], f[nmax][nmax];
int main(int argc, char** argv) {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    f[i][i] = a[i];
  }
  for (int k = 1; k < n; ++k) {
    for (int i = 1; i <= n - k; ++i) {
      a[i] ^= a[i + 1];
      f[i][i + k] = a[i];
    }
  }
  for (int i = n; i; --i)
    for (int j = i + 1; j <= n; ++j) {
      f[i][j] = max(f[i][j], max(f[i + 1][j], f[i][j - 1]));
    }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", f[l][r]);
  }
}
