#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long MX = 1e9;
const long long INF = 1e9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n + 1];
  for (int i = 1; i < n + 1; ++i) cin >> a[i];
  int xr[n + 1], f[n + 1][n + 1];
  xr[0] = 0;
  for (int i = 1; i < n + 1; ++i) xr[i] = a[i] ^ xr[i - 1];
  memset(f, 0, sizeof(f));
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j < n + 1; ++j) {
      if (j + i > n) break;
      if (i == 0)
        f[j][j] = a[j];
      else
        f[j][j + i] = f[j][j + i - 1] ^ f[j + 1][j + i];
    }
  }
  int mx[n + 1][n + 1];
  for (int i = 1; i < n + 1; ++i) {
    for (int j = i; j < n + 1; ++j) {
      if (i == j)
        mx[i][j] = f[i][j];
      else
        mx[i][j] = max(mx[i][j - 1], f[i][j]);
    }
  }
  for (int j = 1; j < n + 1; ++j) {
    for (int i = j - 1; i >= 1; --i) {
      mx[i][j] = max(mx[i][j], mx[i + 1][j]);
    }
  }
  int q, l, r;
  cin >> q;
  while (q--) {
    cin >> l >> r;
    cout << mx[l][r] << '\n';
  }
  return 0;
}
