#include <bits/stdc++.h>
using namespace std;
int n, q;
vector<int> a;
vector<vector<int>> dp1, dp2;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  a.assign(n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  dp1.assign(n + 1, vector<int>(n + 1, 0));
  dp2.assign(n + 1, vector<int>(n + 1, 0));
  for (int i = 0; i < n; ++i) {
    dp1[i][i] = dp2[i][i] = a[i];
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i + j >= n) continue;
      dp1[j][i + j] = dp1[j + 1][i + j] ^ dp1[j][i + j - 1];
      dp2[j][i + j] =
          max(dp1[j][i + j], max(dp2[j + 1][i + j], dp2[j][i + j - 1]));
    }
  }
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    cout << dp2[l][r] << "\n";
  }
  return 0;
}
