#include <bits/stdc++.h>
using namespace std;
const int maxn = 5050;
int f[maxn][maxn];
inline int read() {
  char c = getchar();
  int x = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x;
}
int main() {
  int n = read();
  for (int i = 1; i <= n; i++) f[i][i] = read();
  for (int j = 2; j <= n; j++) {
    int x = 0;
    for (int i = j - 1; i > 0; i--) x ^= f[i][j - 1], f[i][j] = x ^ f[j][j];
  }
  for (int i = n - 1; i > 0; i--)
    for (int j = i + 1; j <= n; j++) {
      int x = max(max(f[i][j - 1], f[i + 1][j]), f[i + 1][j - 1]);
      f[i][j] = max(f[i][j], x);
    }
  int q = read();
  for (int i = 1; i <= q; i++) {
    int l = read(), r = read();
    printf("%d\n", f[l][r]);
  }
  return 0;
}
