#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const int MAXN = 5e5 + 10, MAX = 21;
using namespace std;
int n, q;
int a[MAXN];
struct gauss {
  int n;
  int basis[MAX];
  gauss() { n = 0; }
  int _get() {
    int ans = 0;
    for (int i = 0; i < n; i++) ans = max(ans, ans ^ basis[i]);
    return ans;
  }
  void join(const gauss &other) {
    for (int i = 0; i < other.n; i++) {
      if (n == MAX) return;
      int x = other.basis[i];
      for (int j = 0; j < n; j++) x = min(x, x ^ basis[j]);
      if (x != 0)
        basis[n++] = x;
      else
        continue;
      for (int j = n - 1; j > 0; j--) {
        if (basis[j] > basis[j - 1])
          swap(basis[j], basis[j - 1]);
        else
          break;
      }
    }
  }
  void join(const gauss &a, const gauss &b) {
    *this = a;
    join(b);
  }
};
struct Seg {
  int n;
  gauss aux[MAXN];
  vector<gauss> tree;
  void build() {
    tree.assign(2 * n, gauss());
    for (int i = 0; i < n; i++) tree[n + i] = aux[i + 1];
    for (int i = n - 1; i > 0; i--) tree[i].join(tree[i * 2], tree[i * 2 + 1]);
  }
  int qry(int l, int r) {
    gauss h;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) h.join(tree[l++]);
      if (r & 1) h.join(tree[--r]);
    }
    return h._get();
  }
};
char cc;
void read(int &num) {
  num = 0;
  cc = getchar();
  for (; (cc > 47 && cc < 58); cc = getchar()) num = num * 10 + cc - 48;
}
Seg seg;
int main() {
  read(n);
  seg.n = n;
  for (int i = 1; i < n + 1; i++) {
    read(a[i]);
    if (a[i] == 0) continue;
    seg.aux[i].basis[0] = a[i];
    seg.aux[i].n = 1;
  }
  seg.build();
  read(q);
  vector<int> ans;
  while (q--) {
    int l, r;
    read(l), read(r);
    ans.push_back(seg.qry(l - 1, r));
  }
  for (int i : ans) printf("%d\n", i);
}
