#include <bits/stdc++.h>
const int kMaxCBits = 21;
const int kMaxC = 1000010;
const int kMaxN = 524288;
int leading_bit_memo[kMaxC];
void init_leading_bit_memo() {
  leading_bit_memo[1] = 0;
  for (int i = 2; i < kMaxC; ++i) {
    leading_bit_memo[i] = leading_bit_memo[i / 2] + 1;
  }
}
int bitcount(int x) { return x ? x % 2 + bitcount(x / 2) : 0; }
struct Set {
  Set() : has_vector_mask(0) {}
  static int leading_bit(int x) {
    assert(x > 0);
    return leading_bit_memo[x];
  }
  static bool has_bit(int x, int c) { return !!(x & (1 << c)); }
  int has_vector(int c) const { return has_bit(has_vector_mask, c); }
  void add(int x) {
    assert(x < kMaxC);
    while ((has_vector_mask & x)) {
      int intersection = (has_vector_mask & x);
      x ^= vectors[leading_bit(intersection)];
    }
    if (!x) {
      return;
    }
    int lead_x = leading_bit(x);
    assert(lead_x < kMaxCBits);
    assert(!has_vector(lead_x));
    vectors[lead_x] = x;
    has_vector_mask |= (1 << lead_x);
    for (int i = lead_x + 1; i < kMaxCBits; ++i) {
      if (has_vector(i) && has_bit(vectors[i], lead_x)) {
        vectors[i] ^= x;
      }
    }
  }
  void test_invariants() const {
    for (int i = kMaxCBits - 1; i >= 0; --i) {
      if (!has_vector(i)) {
        continue;
      }
      printf("%2d: ", i);
      for (int j = kMaxCBits - 1; j >= 0; --j) {
        printf("%d", (has_bit(vectors[i], j)));
      }
      printf("\n");
    }
    int max = get_max();
    printf("xx: ");
    for (int j = kMaxCBits - 1; j >= 0; --j) {
      printf("%d", (has_bit(max, j)));
    }
    printf("\n");
    for (int i = 0; i < kMaxCBits; ++i) {
      if (!has_vector(i)) {
        continue;
      }
      assert(leading_bit(vectors[i]) == i);
      for (int j = 0; j < kMaxCBits; ++j) {
        if (i == j || !has_vector(j)) {
          continue;
        }
        assert(!has_bit(vectors[j], i));
      }
    }
  }
  int get_max() const {
    int sol = 0;
    for (int i = kMaxCBits - 1; i >= 0; --i) {
      if (has_vector(i)) {
        assert(has_bit(vectors[i], i));
        if (!has_bit(sol, i)) {
          sol ^= vectors[i];
        }
      }
    }
    return sol;
  }
  int vectors[kMaxCBits];
  int has_vector_mask;
};
Set tournament[kMaxN * 2];
void load() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int c;
    scanf("%d", &c);
    tournament[kMaxN + i].add(c);
  }
}
void merge(const Set& lhs, const Set& rhs, Set* result) {
  if (!lhs.has_vector_mask && !rhs.has_vector_mask) {
    return;
  }
  const Set* _lhs = &lhs;
  const Set* _rhs = &rhs;
  if (bitcount(_lhs->has_vector_mask) > bitcount(_rhs->has_vector_mask)) {
    std::swap(_lhs, _rhs);
  }
  *result = *_rhs;
  for (int i = 0; i < kMaxCBits; ++i) {
    if (_lhs->has_vector(i)) {
      result->add(_lhs->vectors[i]);
    }
  }
}
void mergeTo(const Set& lhs, Set* result) {
  for (int i = 0; i < kMaxCBits; ++i) {
    if (lhs.has_vector(i)) {
      result->add(lhs.vectors[i]);
    }
  }
}
void build() {
  for (int i = kMaxN - 1; i > 0; --i) {
    merge(tournament[i * 2], tournament[i * 2 + 1], &tournament[i]);
  }
}
struct Interval {
  int lo, hi;
  Interval(int lo, int hi) : lo(lo), hi(hi) {
    if (hi < lo) {
      hi = lo;
    }
  }
  Interval split_lo() const { return Interval(lo, (lo + hi) / 2); }
  Interval split_hi() const { return Interval((lo + hi) / 2, hi); }
  bool contains(int x) const { return x >= lo && x < hi; }
  int size() const { return hi - lo; }
  Interval intersection(const Interval& other) const {
    return Interval(std::max(lo, other.lo), std::min(hi, other.hi));
  }
  bool contains(const Interval& other) const {
    return intersection(other).size() == other.size();
  }
  bool intersects(const Interval& other) const {
    return intersection(other).size() > 0;
  }
};
void solve(int node, const Interval& node_interval, const Interval& query,
           Set* result) {
  if (!node_interval.intersects(query)) {
    return;
  }
  if (query.contains(node_interval)) {
    mergeTo(tournament[node], result);
    return;
  }
  solve(node * 2, node_interval.split_lo(), query, result);
  solve(node * 2 + 1, node_interval.split_hi(), query, result);
}
Set brute(const Interval& query) {
  Set result;
  for (int i = query.lo; i < query.hi; ++i) {
    Set tmp = result;
    tournament[kMaxN + i].test_invariants();
    printf("\n");
    merge(tmp, tournament[kMaxN + i], &result);
  }
  result.test_invariants();
  return result;
}
int main() {
  init_leading_bit_memo();
  load();
  build();
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int lo, hi;
    scanf("%d%d", &lo, &hi);
    Interval query(lo - 1, hi);
    Set result;
    solve(1, Interval(0, kMaxN), query, &result);
    printf("%d\n", result.get_max());
  }
  return 0;
}
