#include <bits/stdc++.h>
using namespace std;
int dp[5000][5000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i], dp[0][i] = a[i];
  for (int i = 1; i < n; i++)
    for (int j = 0; j < n - i + 1; j++)
      dp[i][j] = dp[i - 1][j + 1] ^ dp[i - 1][j];
  for (int i = 1; i < n; i++)
    for (int j = 0; j < n - i + 1; j++)
      dp[i][j] = max(dp[i][j], max(dp[i - 1][j + 1], dp[i - 1][j]));
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << dp[r - l][l - 1] << endl;
  }
  return 0;
}
long long choose(long long n, long long k) {
  if (k == 0) return 1;
  return (n * choose(n - 1, k - 1)) / k;
}
bool isprime(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int power(int x, int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
