#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
struct LBase {
  int n, basis[20];
  LBase() { n = 0; }
  inline void insert(int x) {
    if (n == 20) return;
    for (int i = 0; i < n; i++) x = min(x, x ^ basis[i]);
    if (x != 0) {
      basis[n++] = x;
      for (int k = n - 1; k > 0 && basis[k] > basis[k - 1]; k--)
        swap(basis[k], basis[k - 1]);
    }
  }
  inline int getmax() {
    int ret = 0;
    for (int i = 0; i < n; i++) ret = max(ret, ret ^ basis[i]);
    return ret;
  }
} base[maxn << 2];
inline LBase merge(LBase a, LBase b) {
  for (int i = 0; i < b.n; i++) {
    if (b.basis[i]) a.insert(b.basis[i]);
  }
  return a;
}
int a[maxn];
int n, q;
void pushup(int rt) { base[rt] = merge(base[rt << 1], base[rt << 1 | 1]); }
void build(int rt, int l, int r) {
  if (l == r) {
    base[rt].insert(a[l]);
  } else {
    int mid = l + r >> 1;
    build(rt << 1, l, mid);
    build(rt << 1 | 1, mid + 1, r);
    pushup(rt);
  }
}
LBase query(int rt, int l, int r, int ql, int qr) {
  if (ql == l && r == qr) {
    return base[rt];
  } else {
    int mid = l + r >> 1;
    if (qr <= mid)
      return query(rt << 1, l, mid, ql, qr);
    else if (ql > mid)
      return query(rt << 1 | 1, mid + 1, r, ql, qr);
    else {
      return merge(query(rt << 1, l, mid, ql, mid),
                   query(rt << 1 | 1, mid + 1, r, mid + 1, qr));
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  build(1, 1, n);
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    int ans = query(1, 1, n, l, r).getmax();
    printf("%d\n", ans);
  }
  return 0;
}
