#include <bits/stdc++.h>
using namespace std;
struct Basis {
  int basis[21] = {}, index[21] = {};
  void insert(int x, int num) {
    for (int i = 20; i >= 0; i--) {
      if (x & (1 << i)) {
        if (basis[i] == 0) {
          basis[i] = x;
          index[i] = num;
          break;
        } else {
          if (num > index[i]) {
            swap(num, index[i]);
            swap(basis[i], x);
          }
          x = x ^ basis[i];
        }
      }
    }
  }
} f[500100];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1, u; i <= n; i++) {
    scanf("%d", &u);
    f[i] = f[i - 1];
    f[i].insert(u, i);
  }
  scanf("%d", &n);
  while (n--) {
    int l, r, ans = 0;
    scanf("%d%d", &l, &r);
    for (int i = 20; i >= 0; i--) {
      if (f[r].index[i] >= l && ((ans ^ f[r].basis[i]) > ans))
        ans = ans ^ f[r].basis[i];
    }
    printf("%d\n", ans);
  }
}
