#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
int n, q, a[N];
inline char nc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline void read(int &x) {
  char c = nc();
  x = 0;
  for (; c > '9' || c < '0'; c = nc())
    ;
  for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = nc())
    ;
}
void PutAns(long long x) {
  if (x >= 10) PutAns(x / 10);
  putchar(x % 10 + '0');
}
vector<pair<int, int> > v[N], Q[N];
void solve(int m) {
  int len = n - m + 1;
  for (int i = 1; i <= m; i++)
    v[i + len - 1].push_back(pair<int, int>(i, a[i]));
  for (int i = 1; i < m; i++) a[i] ^= a[i + 1];
  if (m ^ 1) solve(m - 1);
}
int ans[100010], mx[N << 2];
void Add(int g, int x, int l, int r, int y) {
  mx[g] = max(mx[g], y);
  if (l == r) return;
  int mid = l + r >> 1;
  if (x <= mid)
    Add(g << 1, x, l, mid, y);
  else
    Add(g << 1 | 1, x, mid + 1, r, y);
}
int Query(int g, int l, int r, int L, int R) {
  if (l == L && r == R) return mx[g];
  int mid = L + R >> 1;
  if (r <= mid)
    return Query(g << 1, l, r, L, mid);
  else if (l > mid)
    return Query(g << 1 | 1, l, r, mid + 1, R);
  return max(Query(g << 1, l, mid, L, mid),
             Query(g << 1 | 1, mid + 1, r, mid + 1, R));
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) read(a[i]);
  solve(n);
  read(q);
  for (int i = 1; i <= q; i++) {
    int l, r;
    read(l);
    read(r);
    Q[r].push_back(pair<int, int>(l, i));
  }
  for (int i = 1; i <= n; i++) {
    for (pair<int, int> x : v[i]) Add(1, x.first, 1, n, x.second);
    for (pair<int, int> x : Q[i]) ans[x.second] = Query(1, x.first, i, 1, n);
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
