#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
using namespace std;
clock_t time_p = clock();
void aryanc403() {
  time_p = clock() - time_p;
  cerr << "Time Taken : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
class CMP {
 public:
  bool operator()(long long int a, long long int b) { return !(a <= b); }
};
void add(map<long long int, long long int> &m, long long int x,
         long long int cnt = 1) {
  map<long long int, long long int>::iterator jt;
  jt = m.find(x);
  if (jt == m.end())
    m.insert(make_pair(x, cnt));
  else
    jt->second += cnt;
}
void del(map<long long int, long long int> &m, long long int x,
         long long int cnt = 1) {
  map<long long int, long long int>::iterator jt;
  jt = m.find(x);
  if (jt->second <= cnt)
    m.erase(jt);
  else
    jt->second -= cnt;
}
bool cmp(const pair<long long int, long long int> &a,
         const pair<long long int, long long int> &b) {
  return a.first < b.first || (a.first == b.first && a.second < b.second);
}
const long long int INF = 0xFFFFFFFFFFFFFFFL;
const long long int mod = 1000000007L;
long long int T, n, i, j, k, in, cnt, l, r;
long long int m;
string s;
vector<long long int> a, final[2000005];
vector<pair<pair<long long int, long long int>, long long int> > qur;
vector<long long int>::iterator it;
void merge(vector<long long int> &ans, const vector<long long int> &b) {
  for (auto x : b) ans.push_back(x);
  long long int i, j, k;
  long long int sz = (long long int)ans.size();
  long long int l = 0;
  for (k = (20); k >= (0); --k) {
    for (j = (l); j <= (sz - 1); ++j) {
      if (ans[j] & (1 << k)) break;
    }
    if (j == sz) continue;
    swap(ans[l], ans[j]);
    for (i = (0); i <= (sz - 1); ++i) {
      if (i != l && ans[i] & (1 << k)) ans[i] ^= ans[l];
    }
    l++;
  }
  if (!ans.empty()) sort(ans.rbegin(), ans.rend());
  while (!ans.empty() && *ans.rbegin() == 0) ans.pop_back();
}
vector<long long int> gauss[500005];
long long int ans[500005];
void add(vector<long long int> &ans, long long int x) {
  long long int k;
  for (auto y : ans) {
    x = min(x, x ^ y);
  }
  if (x) {
    for (auto &y : ans) y = min(y, y ^ x);
    ans.push_back(x);
  }
}
void solve(vector<pair<pair<long long int, long long int>, long long int> > &q,
           long long int l, long long int r) {
  vector<long long int> gs;
  long long int i;
  if (r - l <= 20) {
    vector<long long int> tmp;
    tmp.clear();
    for (auto x : q) {
      gs.clear();
      for (i = (x.first.first); i <= (x.first.second); ++i) add(gs, a[i]);
      for (auto y : gs) ans[x.second] ^= y;
      continue;
      gs.clear();
      for (i = (x.first.first); i <= (x.first.second); ++i) gs.push_back(a[i]);
      merge(gs, tmp);
      for (auto y : gs) {
        ans[x.second] ^= y;
      }
      if (ans[x.second]) {
        cout << "assert failed" << ans[x.second] << "\n";
        exit(0);
      }
    }
    return;
  }
  long long int m = (l + r) / 2;
  gs.clear();
  for (i = (m); i >= (l); --i) {
    add(gs, a[i]);
    gauss[i] = gs;
  }
  gs.clear();
  for (i = (m + 1); i <= (r); ++i) {
    add(gs, a[i]);
    gauss[i] = gs;
  }
  vector<pair<pair<long long int, long long int>, long long int> > lef, rgt;
  lef.clear();
  rgt.clear();
  for (auto x : q) {
    if (x.first.second <= m)
      lef.push_back(x);
    else if (x.first.first > m)
      rgt.push_back(x);
    else {
      gs.clear();
      gs = gauss[x.first.first];
      merge(gs, gauss[x.first.second]);
      ans[x.second] = 0;
      for (auto y : gs) ans[x.second] ^= y;
    }
  }
  q.clear();
  solve(lef, l, m);
  solve(rgt, m + 1, r);
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  {
    cin >> n;
    a.clear();
    a.reserve(n + 1);
    a.push_back(0);
    for (i = 0; i < (n); ++i) {
      cin >> in;
      a.push_back(in);
    }
    long long int q;
    cin >> q;
    for (i = 0; i < (q); ++i) {
      cin >> l >> r;
      qur.push_back({{l, r}, i});
    }
    solve(qur, 1, n);
    for (i = 0; i < (q); ++i) cout << ans[i] << "\n";
  }
  aryanc403();
  return 0;
}
