#include <bits/stdc++.h>
using namespace std;
int n, q;
int C[500001];
vector<pair<int, int> > P[500001];
int ans[500001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> C[i];
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    P[r].emplace_back(l, i);
  }
  pair<int, int> basis[20] = {};
  for (int R = 1; R <= n; ++R) {
    pair<int, int> v(C[R], R);
    for (int i = 20; i--;) {
      if (v.first >> i) {
        if (v.second < basis[i].second)
          v.first ^= basis[i].first;
        else if (basis[i].first == 0) {
          basis[i] = v;
          break;
        } else {
          swap(v, basis[i]);
          v.first ^= basis[i].first;
        }
      }
    }
    for (pair<int, int> _ : P[R]) {
      int L, idx;
      tie(L, idx) = _;
      int v = 0;
      for (int i = 20; i--;) {
        if (basis[i].second < L) continue;
        if (((v >> i) & 1) == 0) v ^= basis[i].first;
      }
      ans[idx] = v;
    }
  }
  for (int i = 0; i < q; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
