#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e3 + 7;
int a[MAX][MAX], b[MAX][MAX];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[1][i];
  for (int i = 2; i <= n; ++i)
    for (int j = 1; j <= n - i + 1; ++j)
      a[i][j] = a[i - 1][j] ^ a[i - 1][j + 1];
  for (int i = 1; i <= n; ++i) b[1][i] = a[1][i];
  for (int i = 2; i <= n; ++i)
    for (int j = 1; j <= n - i + 1; ++j)
      b[i][j] = max(a[i][j], max(b[i - 1][j], b[i - 1][j + 1]));
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    int len = r - l + 1;
    cout << b[len][l] << '\n';
  }
  return 0;
}
