#include <bits/stdc++.h>
const int N = 5005;
int f[N][N];
int dp[N][N];
int val(int l, int r) { return f[r - l][l]; }
int maxim(int a, int b) { return (a > b) ? a : b; }
int maximum(int a, int b, int c) { return maxim(a, maxim(b, c)); }
int main() {
  int len;
  std::cin >> len;
  for (int i = 0; i < len; i += 1) {
    std::cin >> f[0][i];
  }
  for (int i = 1; i < len; i += 1) {
    for (int j = 0; j < len - i; j += 1) {
      f[i][j] = f[i - 1][j] ^ f[i - 1][j + 1];
    }
  }
  for (int i = 0; i < len; i += 1) {
    dp[i][i] = f[0][i];
  }
  for (int r = 0; r < len; r += 1) {
    for (int l = (r > 0) ? r - 1 : 0; l > -1; l += -1) {
      dp[l][r] = maximum(val(l, r), dp[l + 1][r], dp[l][r - 1]);
    }
  }
  int query;
  std::cin >> query;
  for (int i = 0; i < query; i += 1) {
    int l, r;
    std::cin >> l >> r;
    std::cout << dp[l - 1][r - 1] << '\n';
  }
  return 0;
}
