#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[5005][5005];
int sum[5005][5005];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[1][i];
    sum[1][i] = a[1][i];
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= n - i + 1; j++) {
      a[i][j] = sum[i][j] = a[i - 1][j] ^ a[i - 1][j + 1];
      sum[i][j] = max(sum[i - 1][j], max(sum[i][j], sum[i - 1][j + 1]));
    }
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    cout << sum[y - x + 1][x] << endl;
  }
}
