#include <bits/stdc++.h>
using namespace std;
const int BITS = 20;
template <typename T>
struct xor_basis {
  T basis[BITS];
  int n = 0;
  T min_value(T start = 0) const {
    for (int i = 0; i < n; i++) start = min(start, start ^ basis[i]);
    return start;
  }
  T max_value(T start = 0) const {
    for (int i = 0; i < n; i++) start = max(start, start ^ basis[i]);
    return start;
  }
  bool add(T x) {
    if (n == BITS) return false;
    x = min_value(x);
    if (x == 0) return false;
    basis[n++] = x;
    for (int k = n - 1; k > 0 && basis[k] > basis[k - 1]; k--)
      swap(basis[k], basis[k - 1]);
    return true;
  }
  void merge(const xor_basis<T> &other) {
    for (int i = 0; i < other.n && n < BITS; i++) add(other.basis[i]);
  }
};
struct segment {
  xor_basis<int> basis;
  int get_max() const { return basis.max_value(); }
  void join(const segment &other) { basis.merge(other.basis); }
  void join(const segment &a, const segment &b) {
    *this = a;
    join(b);
  }
};
struct basic_seg_tree {
  int tree_n = 0;
  vector<segment> tree;
  basic_seg_tree(int n = 0) {
    if (n > 0) init(n);
  }
  void init(int n) {
    tree_n = n;
    tree.assign(2 * tree_n, segment());
  }
  void build(const vector<segment> &initial) {
    int n = initial.size();
    assert(n <= tree_n);
    for (int i = 0; i < n; i++) tree[tree_n + i] = initial[i];
    for (int position = tree_n - 1; position > 0; position--)
      tree[position].join(tree[2 * position], tree[2 * position + 1]);
  }
  segment query(int a, int b) {
    segment answer;
    for (a += tree_n, b += tree_n; a < b; a /= 2, b /= 2) {
      if (a & 1) answer.join(tree[a++]);
      if (b & 1) answer.join(tree[--b]);
    }
    return answer;
  }
};
int N, Q;
int main() {
  scanf("%d", &N);
  vector<segment> initial;
  for (int i = 0; i < N; i++) {
    int burger;
    scanf("%d", &burger);
    initial.emplace_back();
    initial.back().basis.add(burger);
  }
  basic_seg_tree tree(N);
  tree.build(initial);
  scanf("%d", &Q);
  for (int q = 0; q < Q; q++) {
    int L, R;
    scanf("%d %d", &L, &R);
    L--;
    printf("%d\n", tree.query(L, R).get_max());
  }
}
