#include <bits/stdc++.h>
using namespace std;
int c[505050];
int p[33], cnt;
int f[22];
bool insertv(int v) {
  for (int i = 19; i >= 0; i--)
    if (v & (1 << i)) {
      if (f[i])
        v ^= f[i];
      else {
        f[i] = v;
        return true;
      }
    }
  return false;
}
int getans() {
  int ret = 0;
  for (int i = 19; i >= 0; i--)
    if (((ret >> i) & 1) == 0) ret ^= f[i];
  return ret;
}
int ans[505050];
int l[505050], r[505050], t[505050];
bool cmp(const int &x, const int &y) {
  if (r[x] != r[y]) return r[x] < r[y];
  return l[x] > l[y];
}
int main() {
  int n, q, now = 1, nv;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &l[i], &r[i]);
    t[i] = i;
  }
  sort(t + 1, t + q + 1, cmp);
  for (int i = 1; i <= n; i++) {
    if (c[i]) {
      cnt++;
      for (int j = cnt; j > 1; j--) p[j] = p[j - 1];
      p[1] = i;
    }
    nv = 0;
    memset(f, 0, sizeof(f));
    for (int j = 1; j <= cnt; j++) {
      while (now <= q && r[t[now]] == i && l[t[now]] > p[j]) {
        ans[t[now]] = nv;
        now++;
      }
      if (insertv(c[p[j]]))
        nv = getans();
      else {
        for (int k = j; k < cnt; k++) p[k] = p[k + 1];
        j--;
        cnt--;
      }
    }
    while (now <= q && r[t[now]] == i) {
      ans[t[now]] = nv;
      now++;
    }
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
