#include <bits/stdc++.h>
using namespace std;
struct gauss {
  long long ar[21];
  void clear() {
    for (int i = 0; i <= 20; i++) ar[i] = 0;
  }
  void add(long long x) {
    for (int i = 20; i >= 0; i--) {
      if (ar[i] == 0) ar[i] = x;
      x = min(x, x ^ ar[i]);
    }
  }
  long long max_() {
    long long m = 0;
    for (int i = 20; i >= 0; i--) m = max(m, m ^ ar[i]);
    return m;
  }
};
void func(vector<pair<pair<long long, long long>, long long> >, long long,
          long long);
long long n, q, ar[500005], ans[500005];
struct gauss gr[500005];
vector<pair<pair<long long, long long>, long long> > qr;
int main() {
  scanf("%lld", &n);
  for (int i = 1; i < n + 1; i++) scanf("%lld", &ar[i]);
  scanf("%lld", &q);
  for (int i = 0; i < q; i++) {
    long long x, y;
    scanf("%lld %lld", &x, &y);
    qr.push_back(make_pair(make_pair(x, y), i));
  }
  func(qr, 1, n);
  for (int i = 0; i < q; i++) cout << ans[i] << "\n";
}
void func(vector<pair<pair<long long, long long>, long long> > qr, long long l,
          long long r) {
  if (l > r) return;
  vector<pair<pair<long long, long long>, long long> > qr1, qr2;
  long long mid = (l + r) / 2;
  for (int i = mid; i >= l; i--) {
    if (i == mid) {
      gr[i].clear();
      gr[i].add(ar[i]);
    } else {
      for (int j = 0; j < 21; j++) gr[i].ar[j] = gr[i + 1].ar[j];
      gr[i].add(ar[i]);
    }
  }
  for (int i = mid + 1; i <= r; i++) {
    if (i == mid + 1) {
      gr[i].clear();
      gr[i].add(ar[i]);
    } else {
      for (int j = 0; j < 21; j++) gr[i].ar[j] = gr[i - 1].ar[j];
      gr[i].add(ar[i]);
    }
  }
  for (int i = 0; i < qr.size(); i++) {
    if (mid > qr[i].first.second)
      qr1.push_back(qr[i]);
    else if (mid < qr[i].first.first)
      qr2.push_back(qr[i]);
    else {
      struct gauss temp;
      temp.clear();
      for (int j = 0; j < 21; j++) temp.ar[j] = gr[qr[i].first.first].ar[j];
      for (int j = 0; j < 21; j++) temp.add(gr[qr[i].first.second].ar[j]);
      ans[qr[i].second] = temp.max_();
    }
  }
  func(qr1, l, mid - 1);
  func(qr2, mid + 1, r);
}
