#include <bits/stdc++.h>
using namespace std;
const int LG = 21;
const int N = 500010;
struct Q {
  int l, r, id;
  void scan(int _id) {
    scanf("%d%d", &l, &r);
    id = _id;
  }
} q[N];
int ans[N];
int c[N];
struct Group {
  int fl[LG];
  Group() { memset(fl, 0, sizeof(fl)); }
  void add(int x) {
    for (int i = LG; i >= 0; --i) {
      if ((x >> i) & 1) {
        if (fl[i])
          x ^= fl[i];
        else {
          fl[i] = x;
          break;
        }
      }
    }
  }
  int size() {
    int ans = 0;
    for (int i = 0; i != LG; ++i) ans += !!fl[i];
    return ans;
  }
};
int sum(Group g1, Group g2) {
  for (int i = 0; i != LG; ++i) g1.add(g2.fl[i]);
  int ans = 0;
  for (int i = LG - 1; i >= 0; --i)
    if (!((ans >> i) & 1)) ans ^= g1.fl[i];
  return ans;
}
Q tmp[N];
Group tmp2[N];
void solve(int ql, int qr, int l, int r) {
  if (ql > qr) {
    return;
  }
  if (l == r) {
    for (int i = ql; i <= qr; ++i) ans[q[i].id] = c[l];
    return;
  }
  int mid = (l + r) >> 1;
  int cnt = 0;
  for (int i = ql; i <= qr; ++i) {
    if (q[i].r <= mid) tmp[ql + (cnt++)] = q[i];
  }
  int tcnt = cnt;
  for (int i = ql; i <= qr; ++i) {
    if (q[i].l > mid) tmp[ql + (cnt++)] = q[i];
  }
  int t2cnt = cnt;
  for (int i = ql; i <= qr; ++i) {
    if (q[i].l <= mid && q[i].r > mid) tmp[ql + (cnt++)] = q[i];
  }
  for (int i = ql; i <= qr; ++i) q[i] = tmp[i];
  solve(ql, ql + tcnt - 1, l, mid);
  solve(ql + tcnt, ql + t2cnt - 1, mid + 1, r);
  ql += t2cnt;
  tmp2[mid] = Group();
  tmp2[mid].add(c[mid]);
  for (int i = mid - 1; i >= l; --i) {
    tmp2[i] = tmp2[i + 1];
    tmp2[i].add(c[i]);
  }
  tmp2[mid + 1] = Group();
  tmp2[mid + 1].add(c[mid + 1]);
  for (int i = mid + 2; i <= r; ++i) {
    tmp2[i] = tmp2[i - 1];
    tmp2[i].add(c[i]);
  }
  for (int i = ql; i <= qr; ++i) {
    ans[q[i].id] = sum(tmp2[q[i].l], tmp2[q[i].r]);
  }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]);
  int Q;
  scanf("%d", &Q);
  for (int i = 1; i <= Q; ++i) q[i].scan(i);
  solve(1, Q, 1, n);
  for (int i = 1; i <= Q; ++i) printf("%d\n", ans[i]);
}
