#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 500;
const int sze = 20;
inline int read() {
  char ch;
  while ((ch = getchar()) < '0' || ch > '9')
    ;
  int res = ch - '0';
  while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - '0';
  return res;
}
int blg[N], q[21], p[25010][20][21], n, m, lg[25010], d[N];
void ins(int *s, int val, int num) {
  for (int i = num; i >= 0; i--)
    if ((val >> i) & 1) {
      if (!s[i]) s[i] = val;
      if (!(val ^= s[i])) return;
    }
}
void mrge(int *p1, int *p2) {
  for (int i = 20; i >= 0; i--)
    if (p1[i]) ins(p2, p1[i], i);
}
int qry() {
  int val = 0;
  for (int i = 20; i >= 0; i--)
    if ((val ^ q[i]) > val) val ^= q[i];
  return val;
}
int main() {
  n = read();
  int tot = ceil((double)n / sze);
  for (int i = 2; i <= 25000; i++) lg[i] = lg[i >> 1] + 1;
  int x, l, r;
  for (int i = 1, l = 1, r = min(sze, n); i <= tot;
       l += sze, r = min(r + sze, n), i++)
    for (int j = l; j <= r; j++) {
      blg[j] = i;
      d[j] = read();
      ins(p[i][0], d[j], 20);
    }
  for (int j = 1; j <= lg[tot]; j++)
    for (int i = 1; i + (1 << j) - 1 <= tot; i++)
      mrge(p[i][j - 1], p[i][j]), mrge(p[i + (1 << j - 1)][j - 1], p[i][j]);
  m = read();
  while (m--) {
    l = read();
    r = read();
    int ll = blg[l], rr = blg[r];
    memset(q, 0, sizeof(q));
    if (ll + 1 >= rr) {
      for (int i = l; i <= r; i++) ins(q, d[i], 20);
    } else {
      int k = lg[rr - ll - 1];
      mrge(p[ll + 1][k], q);
      mrge(p[rr - (1 << k)][k], q);
      for (int i = l; i <= ll * sze; i++) ins(q, d[i], 20);
      for (int i = sze * (rr - 1) + 1; i <= r; i++) ins(q, d[i], 20);
    }
    printf("%d\n", qry());
  }
  return 0;
}
