#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000007;
long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f * x;
}
int f[5005][5005], d[5005][5005], n, m, _x, _y, a[5005];
bool v[5005][5005];
void dfs(int x, int y) {
  if (v[x][y]) return;
  if (x == y) {
    d[x][y] = f[x][y] = a[x];
    v[x][y]++;
    return;
  }
  v[x][y]++;
  dfs(x + 1, y);
  dfs(x, y - 1);
  f[x][y] = f[x + 1][y] ^ f[x][y - 1];
  d[x][y] = max(f[x][y], max(d[x + 1][y], d[x][y - 1]));
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  dfs(1, n);
  m = read();
  while (m--) {
    _x = read();
    _y = read();
    printf("%d\n", d[_x][_y]);
  }
  return 0;
}
