#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int a[maxn], b[32], pos[32];
int base[maxn][32], las[maxn][32];
void add(int val, int p) {
  for (int i = 30; i >= 0; i--) {
    if (val & (1ll << i)) {
      if (!b[i]) {
        pos[i] = p;
        b[i] = val;
        break;
      }
      if (pos[i] < p) {
        swap(b[i], val);
        swap(pos[i], p);
      }
      val ^= b[i];
    }
  }
}
int main() {
  int n, q;
  scanf("%d", &n);
  for (int i = 30; i >= 0; i--) b[i] = pos[i] = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    add(a[i], i);
    for (int j = 30; j >= 0; j--) base[i][j] = b[j], las[i][j] = pos[j];
  }
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    int lastans = 0;
    for (int i = 30; i >= 0; i--) {
      if (las[r][i] >= l && (lastans ^ base[r][i]) > lastans)
        lastans ^= base[r][i];
    }
    printf("%d\n", lastans);
  }
  return 0;
}
