#include <bits/stdc++.h>
using namespace std;
int c[500005];
int n, q;
int L[500005], R[500005];
vector<int> qur[500005];
vector<int> basis[500005], sol[500005];
vector<int> temp;
bool cmp(int i, int j) { return R[i] < R[j]; }
vector<int> merge(int A, int B) {
  vector<int> d(20, 0);
  for (int i = 0; i <= 19; i++) d[i] = basis[A][i];
  for (auto j : basis[B]) {
    int x = j;
    for (int jj = 19; jj >= 0 && x; jj--) {
      if (((1 << jj) & x)) {
        if (d[jj])
          x ^= d[jj];
        else {
          d[jj] = x;
          break;
        }
      }
    }
  }
  return d;
}
void add(vector<int>& a, int x) {
  for (int j = 19; j >= 0; j--)
    if ((x & (1 << j))) {
      if (a[j])
        x ^= a[j];
      else {
        a[j] = x;
        break;
      }
    }
}
int get(vector<int>& a) {
  int res = 0;
  for (int j = 19; j >= 0; j--) res = max(res, res ^ a[j]);
  return res;
}
void solve(int l, int r) {
  if (r == l) {
    for (auto j : qur[l]) add(sol[j], c[l]);
    return;
  }
  int mid = (l + r) >> 1;
  temp.clear();
  temp.resize(20);
  for (int i = mid; i >= l; i--) {
    add(temp, c[i]);
    basis[i] = temp;
  }
  temp.clear();
  temp.resize(20);
  for (int i = mid + 1; i <= r; i++) {
    add(temp, c[i]);
    basis[i] = temp;
  }
  for (int i = l; i <= mid; i++) {
    while (qur[i].size() && R[qur[i].back()] > mid) {
      int j = qur[i].back();
      sol[j] = merge(i, R[j]);
      qur[i].pop_back();
    }
  }
  solve(l, mid);
  solve(mid + 1, r);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i], basis[i] = vector<int>(20, 0);
  cin >> q;
  for (int i = 1; i <= q; i++) {
    sol[i] = vector<int>(20, 0);
    int l, r;
    cin >> l >> r;
    L[i] = l, R[i] = r;
    qur[l].push_back(i);
  }
  for (int i = 1; i <= n; i++) sort(qur[i].begin(), qur[i].end(), cmp);
  solve(1, n);
  for (int i = 1; i <= q; i++) cout << get(sol[i]) << '\n';
  return 0;
}
