#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static const int BS = 1 << 22;
  static unsigned char buf[BS], *st, *ed;
  if (st == ed) ed = buf + fread(st = buf, 1, BS, stdin);
  return st == ed ? EOF : *st++;
}
template <class T>
void in(T &x) {
  x = 0;
  bool f = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while ('0' <= c && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  if (f) x = -x;
}
int v[5005][5005];
int qmx[5005][5005];
int f[5005][5005];
int n;
inline int mmax(const int &a, const int &b) { return a > b ? a : b; }
signed main() {
  in(n);
  for (register int i = 1; i <= n; ++i) in(v[1][i]);
  for (register int i = 2, mj = n - 1; i <= n; ++i, --mj) {
    for (register int j = 1; j <= mj; ++j) {
      v[i][j] = v[i - 1][j] ^ v[i - 1][j + 1];
    }
  }
  for (register int j = 1, mi = n; j <= n; ++j, --mi)
    for (register int i = 1; i <= mi; ++i)
      qmx[i][j] = mmax(v[i][j], qmx[i - 1][j]);
  for (register int i = n; i >= 1; --i) {
    f[i][i] = qmx[1][i];
    for (register int j = i - 1; j >= 1; --j)
      f[j][i] = mmax(qmx[i - j + 1][j], f[j + 1][i]);
  }
  int q, l, r;
  in(q);
  while (q--) {
    in(l), in(r);
    printf("%d\n", f[l][r]);
  }
  return 0;
}
