#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
int n, d[5050], q, l, r, pre[5050][5050], dp[5050][5050];
bool chk[5050][5050], chk2[5050][5050];
int f(int x, int y) {
  if (chk[x][y]) return dp[x][y];
  chk[x][y] = 1;
  if (x == y) return dp[x][y] = d[x];
  int ans;
  ans = max(f(x, y - 1), f(x + 1, y));
  ans = max(ans, pre[x][y]);
  return dp[x][y] = ans;
}
int pr(int x, int y) {
  if (x > y) return 0;
  if (chk2[x][y]) return pre[x][y];
  chk2[x][y] = 1;
  if (x == y) return pre[x][y] = d[x];
  return pre[x][y] = pr(x, y - 1) ^ pr(x + 1, y);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &d[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) pre[i][j] = pr(i, j);
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%d %d", &l, &r);
    printf("%d\n", f(l, r));
  }
}
