#include <bits/stdc++.h>
using namespace std;
int d[32], pos[32], base[500005][32], las[500005][32];
int a[500005];
void add(int x, int pp) {
  for (int i = 30; i >= 0; i--) {
    if (x & ((1ll) << i)) {
      if (pos[i] < pp) {
        swap(d[i], x);
        swap(pos[i], pp);
      }
      if (d[i]) {
        x = x ^ d[i];
      } else {
        d[i] = x;
        pos[i] = pp;
        break;
      }
    }
  }
}
int main() {
  int t;
  int n, m;
  int op, l, r, ans;
  cin >> n;
  for (int i = 0; i < 32; i++) {
    d[i] = 0;
    pos[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
    add(a[i], i + 1);
    for (int j = 30; j >= 0; --j) base[i + 1][j] = d[j], las[i + 1][j] = pos[j];
  }
  int lastans = 0;
  cin >> m;
  while (m--) {
    scanf("%d%d", &l, &r);
    if (l > r) {
      swap(l, r);
    }
    lastans = 0;
    for (int i = 30; i >= 0; --i) {
      if (las[r][i] >= l && (lastans ^ base[r][i]) > lastans) {
        lastans ^= base[r][i];
      }
    }
    cout << lastans << endl;
  }
}
