#include <bits/stdc++.h>
using namespace std;
const int bit = 21;
int n, q, l, r;
vector<int> c, res, ans, Gauss(bit), in(bit, -1);
vector<vector<pair<int, int>>> cur;
void add(int cat, int id) {
  for (int i = bit - 2; i >= 0; i--) {
    if ((cat >> i) & 1) {
      if (Gauss[i]) {
        if (id > in[i]) {
          swap(cat, Gauss[i]);
          swap(id, in[i]);
        }
        cat ^= Gauss[i];
      } else {
        Gauss[i] = cat;
        in[i] = id;
        return;
      }
    }
  }
}
int get(int id) {
  int res = 0;
  for (int i = bit - 1; i >= 0; i--)
    if (in[i] >= id) res = max(res, res ^ Gauss[i]);
  return res;
}
int main() {
  scanf("%d", &n);
  c.resize(n);
  res.resize(n);
  cur.resize(n);
  for (int i = 0; i < n; i++) scanf("%d", &c[i]);
  scanf("%d", &q);
  ans.resize(q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &l, &r);
    l--;
    r--;
    cur[r].push_back(make_pair(l, i));
  }
  for (int i = 0; i < n; i++) {
    add(c[i], i);
    for (auto j : cur[i]) {
      int l = j.first, id = j.second;
      ans[id] = get(l);
    }
  }
  for (int i = 0; i < q; i++) printf("%d\n", ans[i]);
  return 0;
}
