#include <bits/stdc++.h>
template <typename T>
extern inline void SWAP(T &a, T &b) {
  T t = a;
  a = b, b = t;
}
const int MAXN = 500005;
const int MAXBIT = 20;
const int MEMBIT = MAXBIT + 5;
int bas[MEMBIT], pos[MEMBIT], n, rt, a[MAXN], q;
struct quest {
  int lt, rt, id;
  bool operator<(const quest &tmp) const { return rt < tmp.rt; }
} Q[MAXN];
void insert(int x, int id) {
  for (register int i = (MAXBIT); i >= (0); --i) {
    if (x & (1 << i)) {
      if (!bas[i]) {
        bas[i] = x, pos[i] = id;
        return;
      }
      if (pos[i] < id) SWAP(pos[i], id), SWAP(x, bas[i]);
      x ^= bas[i];
    }
  }
}
int work(int lt) {
  int ans = 0;
  for (register int i = (MAXBIT); i >= (0); --i)
    if (pos[i] >= lt && ans < (ans ^ bas[i])) ans ^= bas[i];
  return ans;
}
int ans[MAXN];
int main() {
  scanf("%d", &n);
  for (register int i = (1); i <= (n); ++i) scanf("%d", &a[i]);
  scanf("%d", &q);
  for (register int i = (1); i <= (q); ++i)
    scanf("%d%d", &Q[i].lt, &Q[i].rt), Q[i].id = i;
  std::sort(Q + 1, Q + 1 + q);
  for (register int i = (1); i <= (q); ++i) {
    while (rt < Q[i].rt) {
      ++rt;
      insert(a[rt], rt);
    }
    ans[Q[i].id] = work(Q[i].lt);
  }
  for (register int i = (1); i <= (q); ++i) printf("%d\n", ans[i]);
  return 0;
}
