#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int a[maxn], n, pos[21], base[21], ans[maxn];
struct que {
  int l, r, id;
  bool operator<(const que &a) const { return r < a.r; }
} q[maxn];
void LIN(int x, int id) {
  for (int i = 20; i >= 0; i--) {
    if (!(x >> i)) continue;
    if (!base[i]) {
      base[i] = x;
      pos[i] = id;
      return;
    }
    if (pos[i] < id) swap(id, pos[i]), swap(base[i], x);
    x ^= base[i];
  }
}
int work(int l) {
  int ans = 0;
  for (int i = 20; i >= 0; i--)
    if (pos[i] >= l && (ans ^ base[i]) > ans) ans ^= base[i];
  return ans;
}
int main() {
  int k;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &k);
  for (int i = 1; i <= k; i++) {
    scanf("%d %d", &q[i].l, &q[i].r);
    q[i].id = i;
  }
  sort(q + 1, q + k + 1);
  int r = 0;
  for (int i = 1; i <= k; i++) {
    while (r < q[i].r) {
      r++;
      LIN(a[r], r);
    }
    ans[q[i].id] = work(q[i].l);
  }
  for (int i = 1; i <= k; i++) printf("%d\n", ans[i]);
  return 0;
}
