#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 9, maxq = 5e5 + 9, bit = 20;
int n, q, c[maxn], a[bit], p[bit], res[maxq];
vector<pair<int, int> > qrs[maxn];
void insert(int x, int pos) {
  for (int i = (bit)-1; i >= (0); --i)
    if (x & (1 << i)) {
      if (a[i]) {
        if (p[i] < pos) swap(a[i], x), swap(p[i], pos);
        x ^= a[i];
      } else {
        a[i] = x, p[i] = pos;
        break;
      }
    }
}
int main() {
  cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = (0); i < (n); ++i) cin >> c[i];
  cin >> q;
  for (int i = (0); i < (q); ++i) {
    int l, r;
    cin >> l >> r, --l, --r;
    qrs[r].push_back(pair<int, int>(l, i));
  }
  memset(a, (0), sizeof a);
  memset(p, (0), sizeof p);
  memset(res, (0), sizeof res);
  for (int i = (0); i < (n); ++i) {
    insert(c[i], i);
    for (int j = (0); j < (qrs[i].size()); ++j) {
      pair<int, int> qq = qrs[i][j];
      for (int k = (bit)-1; k >= (0); --k)
        if (!(res[qq.second] & (1 << k)) && qq.first <= p[k])
          res[qq.second] ^= a[k];
    }
  }
  for (int i = (0); i < (q); ++i) cout << res[i] << endl;
}
