#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 7;
const long long INF = 1e18 + 5;
const long long maxn = 5e5 + 5;
long long n = 100000000000, a[555555], d[555555], mx = -1000000001;
long long u[1511111], b[1100005], sum, cnt, p[555555];
long long bi(long long x, long long y) {
  if (y == 0) return 1ll;
  if (y == 1) return x;
  long long z = bi(x, y / 2);
  z = z * z % n;
  if (y & 1) z = z * x % n;
  return z % n;
}
int c[5001][5001];
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(NULL);
  int n, q;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], p[i] = (a[i] ^ p[i - 1]);
  cin >> q;
  for (int i = 1; i <= n; i++) c[i][i] = a[i];
  for (int l = 1; l <= n - 1; l++)
    for (int i = 1; i <= n; i++)
      if (i + l <= n) c[i][i + l] = c[i][i + l - 1] ^ c[i + 1][i + l];
  for (int l = 1; l <= n - 1; l++)
    for (int i = 1; i <= n; i++)
      if (i + l <= n)
        c[i][i + l] = max(c[i][i + l], max(c[i + 1][i + l], c[i][i + l - 1]));
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << c[l][r] << endl;
  }
  return 0;
}
