#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7, LIM = 20;
int d[LIM + 3][N], pos[LIM + 3][N], a[N];
void insert(int q, int x) {
  int p = q + 1;
  for (int i = 0; i <= LIM; ++i) d[i][p] = d[i][q], pos[i][p] = pos[i][q];
  int c_pos = p;
  for (int i = LIM; i >= 0; --i) {
    if (!(x >> i & 1)) continue;
    if (d[i][p]) {
      if (pos[i][p] < c_pos) {
        swap(d[i][p], x);
        swap(pos[i][p], c_pos);
      }
      x ^= d[i][p];
    } else {
      d[i][p] = x;
      pos[i][p] = c_pos;
      return;
    }
  }
}
int query(int l, int r) {
  int res = 0;
  for (int i = LIM; i >= 0; --i)
    if (pos[i][r] >= l && res < (res ^ d[i][r])) res ^= d[i][r];
  return res;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), insert(i - 1, a[i]);
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", query(l, r));
  }
  return 0;
}
