#include <bits/stdc++.h>
#pragma GCC optimize("-O2")
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
const int LIM = 1e5 + 5, MOD = 1e9 + 7;
int t, n, m, k, x, y;
int ans[5005][5005], val[5005][5005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    for (int j = i; j >= 0; j--) {
      if (j == i)
        val[j][i] = ans[j][i] = a[i];
      else {
        val[j][i] = ans[j][i] = val[j][i - 1] ^ val[j + 1][i];
        ans[j][i] = max(ans[j][i], ans[j][i - 1]);
        ans[j][i] = max(ans[j][i], ans[j + 1][i]);
      }
    }
  }
  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> x >> y;
    x--;
    y--;
    cout << ans[x][y] << "\n";
  }
  return 0;
}
