#include <bits/stdc++.h>
using namespace std;
class qry {
 public:
  int l, r, idx;
  qry(int l, int r, int idx) : l(l), r(r), idx(idx) {}
};
int a[500001], n, m, res[500001];
vector<qry> q;
int getans(vector<int> b) {
  int res = 0;
  for (int i = 0; i < b.size(); i++) {
    if ((res ^ b[i]) > res) res ^= b[i];
  }
  return res;
}
void ins(vector<int>& b, int x) {
  for (int i = 0; i < b.size(); i++) {
    if ((b[i] ^ x) < x) x ^= b[i];
  }
  if (!x) return;
  int t = 31 - __builtin_clz(x);
  for (int i = 0; i < b.size(); i++) {
    if (b[i] & (1 << t)) b[i] ^= x;
  }
  b.push_back(x);
}
vector<int> merge(vector<int>& a, vector<int>& b) {
  vector<int> ret = a;
  for (int i = 0; i < b.size(); i++) ins(ret, b[i]);
  return ret;
}
void solve(vector<qry>& q, int L, int R) {
  if (q.empty()) return;
  if (q.size() <= 3 || R - L <= 3) {
    for (int i = 0; i < q.size(); i++) {
      int l = q[i].l, r = q[i].r;
      vector<int> bs;
      for (int j = l; j <= r; j++) ins(bs, a[j]);
      res[q[i].idx] = getans(bs);
    }
    return;
  }
  vector<qry> l, r, my;
  int mid = (L + R) / 2;
  for (int i = 0; i < q.size(); i++) {
    if (q[i].r <= mid)
      l.push_back(q[i]);
    else if (q[i].l >= mid + 1)
      r.push_back(q[i]);
    else
      my.push_back(q[i]);
  }
  solve(l, L, mid);
  solve(r, mid + 1, R);
  sort(my.begin(), my.end(), [](const qry& i, const qry& j) {
    if (i.l != j.l)
      return i.l > j.l;
    else
      return i.r < j.r;
  });
  vector<int> lb;
  int cur = 0, pt = mid;
  vector<vector<int> > rb;
  vector<int> t;
  for (int i = mid + 1; i <= R; i++) {
    ins(t, a[i]);
    rb.push_back(t);
  }
  while (cur < my.size()) {
    bool found = false;
    while (my[cur].l <= pt) {
      found = true;
      ins(lb, a[pt--]);
    }
    res[my[cur].idx] = getans(merge(lb, rb[my[cur].r - mid - 1]));
    cur++;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    q.push_back(qry(l, r, i));
  }
  solve(q, 1, n);
  for (int i = 1; i <= m; i++) printf("%d\n", res[i]);
  return 0;
}
