#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5 + 7;
int n, Q;
int a[MAXN];
int bsc[MAXN][22], lst[MAXN][22];
int main() {
  scanf("%d", &n);
  for (int i = 1, t, npos; i <= n; ++i) {
    scanf("%d", &a[i]);
    for (int k = 0; k <= 21; ++k)
      bsc[i][k] = bsc[i - 1][k], lst[i][k] = lst[i - 1][k];
    t = a[i];
    npos = i;
    for (int k = 21; k >= 0; --k) {
      if (!(t >> k) & 1) continue;
      if (!bsc[i][k]) {
        bsc[i][k] = t;
        lst[i][k] = npos;
        break;
      }
      if (lst[i][k] < npos) {
        swap(t, bsc[i][k]);
        swap(lst[i][k], npos);
      }
      t ^= bsc[i][k];
    }
  }
  scanf("%d", &Q);
  for (int i = 1, x, y; i <= Q; ++i) {
    scanf("%d%d", &x, &y);
    int ans = 0;
    for (int k = 21; k >= 0; --k) {
      if (lst[y][k] >= x && (ans ^ bsc[y][k]) > ans) ans ^= bsc[y][k];
    }
    printf("%d\n", ans);
  }
  return 0;
}
