#include <bits/stdc++.h>
const int maxn = 5e5 + 5;
const int logn = 21;
const int lim = 2e1;
const int maxq = 5e5 + 5;
struct ques {
  int l;
  int r;
  int id;
  friend bool operator<(ques now, ques oth) { return now.r < oth.r; }
} qu[maxq];
int base[logn], wz[logn];
void insert(int gave, int id) {
  for (int i = lim; i >= 0; i--) {
    if (!(gave >> i & 1)) continue;
    if (!base[i]) {
      base[i] = gave;
      wz[i] = id;
      return;
    }
    if (wz[i] < id) {
      std::swap(wz[i], id);
      std::swap(base[i], gave);
    }
    gave ^= base[i];
  }
  return;
}
int tian(int lef) {
  int res = 0;
  for (int i = lim; i >= 0; i--)
    if (wz[i] >= lef) res = std::max(res, res ^ base[i]);
  return res;
}
int out[maxq];
int n, q;
int val[maxn];
signed main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", val + i);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &qu[i].l, &qu[i].r);
    qu[i].id = i;
  }
  std::sort(qu + 1, qu + q + 1);
  int nr = 0;
  for (int i = 1; i <= q; i++) {
    while (nr < qu[i].r) {
      nr++;
      insert(val[nr], nr);
    }
    out[qu[i].id] = tian(qu[i].l);
  }
  for (int i = 1; i <= q; i++) printf("%d\n", out[i]);
  return 0;
}
