#include <bits/stdc++.h>
using namespace std;
const int MAX = 5e5 + 10;
int arr[MAX];
int n;
vector<pair<int, int> > queries[MAX];
int ans[MAX];
int basis[24], last[24];
void add(int x, int idx) {
  for (int bit = 20; bit >= 0; --bit) {
    if (!(x & (1 << bit))) continue;
    if (idx > last[bit]) {
      int a = basis[bit], b = last[bit];
      basis[bit] = x, last[bit] = idx;
      add(a, b);
      break;
    }
    x ^= basis[bit];
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> arr[i];
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    queries[r].emplace_back(l, i);
  }
  for (int i = 1; i <= n; ++i) {
    add(arr[i], i);
    for (auto &p : queries[i]) {
      int l = p.first, idx = p.second;
      for (int bit = 20; bit >= 0; --bit) {
        if ((ans[idx] & (1 << bit))) continue;
        if (last[bit] < l) continue;
        ans[idx] ^= basis[bit];
      }
    }
  }
  for (int i = 0; i < q; ++i) cout << ans[i] << "\n";
  return 0;
}
