#include <bits/stdc++.h>
using namespace std;
const int seed = 131;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int MAXL = 31;
const int M = 5e5 + 5;
int a[maxn][MAXL + 1];
int pos[M][MAXL + 1];
void Insert(int id, int t, int p) {
  for (int j = MAXL; j >= 0; j--) {
    if (!(t & (1 << j))) continue;
    if (!a[j]) {
      a[id][j] = t;
      pos[id][j] = p;
      break;
    }
    if (pos[id][j] < p) {
      swap(pos[id][j], p);
      swap(a[id][j], t);
    }
    t ^= a[id][j];
  }
}
int x;
int l, r;
int T, n, m;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    for (int j = MAXL; j >= 0; j--) {
      pos[i][j] = pos[i - 1][j];
      a[i][j] = a[i - 1][j];
    }
    Insert(i, x, i);
  }
  scanf("%d", &m);
  int lastans = 0;
  while (m--) {
    int op;
    scanf("%d%d", &l, &r);
    int num = 0;
    for (int j = MAXL; j >= 0; j--) {
      if (pos[r][j] < l) continue;
      if ((num ^ a[r][j]) > num) num ^= a[r][j];
    }
    printf("%d\n", num);
    lastans = num;
  }
  return 0;
}
