#include <bits/stdc++.h>
using namespace std;
long long b[5003];
long long ans[5003][5003];
int n, a, c;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> b[i];
    ans[i][0] = b[i];
  }
  for (int sz = 1; sz < n; sz++) {
    for (int j = 0; j + sz <= n; j++) {
      if (j + 1 < n) ans[j][sz] = ans[j][sz - 1] ^ ans[j + 1][sz - 1];
    }
  }
  for (int sz = 1; sz < n; sz++) {
    for (int j = 0; j + sz < n; j++) {
      ans[j][sz] = max(max(ans[j][sz], ans[j][sz - 1]), ans[j + 1][sz - 1]);
    }
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> c;
    cout << ans[a - 1][c - a] << endl;
  }
}
