#include <bits/stdc++.h>
using namespace std;
template <class T>
ostream& operator<<(ostream& cout, vector<T> V) {
  cout << "[ ";
  for (auto v : V) cout << v << ' ';
  return cout << ']';
}
template <class L, class R>
ostream& operator<<(ostream& cout, pair<L, R> P) {
  return cout << '(' << P.first << ',' << P.second << ')';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<vector<int>> dp(n, vector<int>(n));
  vector<int> a(n);
  for (int i = 0; i < (n); i++) cin >> a[i];
  for (int i = 0; i < (n); i++) dp[i][i] = a[i];
  for (int i = 1; i < n; i++) {
    for (int j = 0; i + j < n; j++) {
      dp[j][i + j] = (dp[j][i + j - 1] ^ dp[j + 1][i + j]);
    }
  }
  vector<vector<int>> ma(n, vector<int>(n));
  for (int i = 0; i < (n); i++) {
    ma[i][0] = dp[i][0];
    for (int j = 1; j < n; j++) {
      ma[i][j] = max(ma[i][j - 1], dp[i][j]);
    }
  }
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (n); j++) dp[i][j] = 0;
  for (int i = 0; i < (n); i++) dp[i][i] = a[i];
  for (int i = 1; i < n; i++) {
    for (int j = 0; i + j < n; j++) {
      dp[j][i + j] = max(dp[j + 1][i + j], ma[j][i + j]);
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int l;
    cin >> l;
    int r;
    cin >> r;
    l--, r--;
    cout << dp[l][r] << '\n';
  }
  cerr << "Time : " << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC
       << "ms\n";
  ;
}
