#include <bits/stdc++.h>
const long long MOD = 1000 * 1000 * 1000 + 7;
const long long MOD1 = 998244353;
const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
using namespace std;
long long power(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y & 1) res = (long long)(res * x);
    y = y >> 1;
    if (x <= 100000000) x = (long long)(x * x);
  }
  return res;
}
long long val[5001][5001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long a[n + 1];
  for (int(i) = (1); (i) < (n + 1); ++(i)) {
    cin >> a[i];
    val[i][i] = a[i];
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= n - i + 1; j++) {
      val[j][j + i - 1] = val[j][j + i - 2] ^ val[j + 1][j + i - 1];
    }
  }
  for (int i = 2; i <= n; i++) {
    for (int j = 1; j <= n - i + 1; j++) {
      val[j][j + i - 1] =
          max(val[j][j + i - 1], max(val[j][j + i - 2], val[j + 1][j + i - 1]));
    }
  }
  long long q;
  cin >> q;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    cout << val[x][y] << "\n";
  }
  return 0;
}
