#include <bits/stdc++.h>
using namespace std;
const int MAXL = 20;
struct LinearBasis {
  int a[MAXL];
  int n;
  explicit LinearBasis() : n(0) {}
  LinearBasis(const LinearBasis &other) {
    n = other.n;
    std::memcpy(a, other.a, sizeof other.a);
  }
  void insert(int x) {
    if (n == MAXL) return;
    for (int j = 0; j < n; ++j)
      if ((x ^ a[j]) < x) x ^= a[j];
    if (x) {
      a[n++] = x;
      for (int k = n - 1; k > 0 && a[k] > a[k - 1]; --k) swap(a[k], a[k - 1]);
    }
  }
  friend std::ostream &operator<<(std::ostream &os, LinearBasis &lb) {
    os << '[';
    for (int j = lb.n - 1; j >= 0; --j) {
      if (j != lb.n - 1) os << ", ";
      os << lb.a[j];
    }
    os << ']';
    return os;
  }
  void join(const LinearBasis &a, const LinearBasis &b) {
    std::memcpy(this->a, a.a, sizeof a.a);
    n = a.n;
    operator+=(b);
  }
  void operator+=(const LinearBasis &other) {
    if (n == MAXL) return;
    for (int i = 0; i < other.n; ++i) insert(other.a[i]);
  }
  int max() const {
    int ans = 0;
    for (int i = 0; i < n; ++i)
      if ((ans ^ a[i]) > ans) ans ^= a[i];
    return ans;
  }
};
struct SegmentTree {
  vector<LinearBasis> tree;
  int len;
  SegmentTree() : len(0) {}
  void pushup(int i) { tree[i].join(tree[i << 1], tree[i << 1 | 1]); }
  void build(int n) {
    len = n;
    tree.assign(n << 1, LinearBasis());
    int temp;
    for (int i = 0; i < len; ++i)
      std::scanf("%d", &temp), tree[len + i].a[0] = temp,
                                          tree[len + i].n = (temp == 0 ? 0 : 1);
    for (int j = len - 1; j >= 1; --j) pushup(j);
  }
  int query(int l, int r) const {
    LinearBasis temp;
    for (l += len, r += len; l < r; l >>= 1, r >>= 1) {
      if (l & 1) temp += tree[l++];
      if (r & 1) temp += tree[--r];
    }
    return temp.max();
  }
};
int main() {
  SegmentTree st;
  int n;
  std::scanf("%d", &n);
  st.build(n);
  int q, l, r;
  std::scanf("%d", &q);
  while (q--) {
    std::scanf("%d%d", &l, &r);
    std::printf("%d\n", st.query(l - 1, r));
  }
  return 0;
}
