#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500050;
struct Query {
  int l, r, id;
  void in(int _id) {
    scanf("%d %d", &l, &r);
    --l;
    id = _id;
  }
};
void add_element(vector<int> &x, int b) {
  if (b == 0) return;
  int where = 0;
  for (int i = (0); i < (int)(((int)x.size())); i++) {
    int pos = (31 - __builtin_clz(x[i]));
    int pos_cand = (31 - __builtin_clz(b));
    if (pos >= pos_cand) {
      if (b & (1 << pos)) {
        b ^= x[i];
      }
    } else {
      where = i;
      break;
    }
    if (b == 0) break;
  }
  if (b == 0) return;
  if (!((int)x.size()) || x.back() > b)
    x.push_back(b);
  else
    x.insert(x.begin() + where, b);
  assert(((int)x.size()) <= 20);
}
vector<int> oper(const vector<int> &a, const vector<int> &b) {
  vector<int> x = a;
  for (int i = (0); i < (int)(((int)b.size())); i++) add_element(x, b[i]);
  return x;
}
int n, q, A[MAXN], ans[MAXN];
vector<Query> Q;
void solve(int l, int r, vector<Query> Q) {
  int m = l + (r - l) / 2;
  vector<Query> q1, q2, q0;
  for (Query q : Q) {
    if (q.r <= m)
      q1.push_back(q);
    else if (q.l >= m)
      q2.push_back(q);
    else
      q0.push_back(q);
  }
  if (l + 1 != r) {
    solve(l, m, q1);
    solve(m, r, q2);
  } else {
    for (Query q : Q) {
      ans[q.id] = A[q.l];
    }
    return;
  }
  vector<vector<int>> L(r - l);
  vector<vector<int>> R(r - l);
  vector<int> curr(0);
  for (int i = m - 1; i >= l; i--) {
    add_element(curr, A[i]);
    L[i - l] = curr;
  }
  curr = vector<int>(0);
  for (int i = m; i < r; i++) {
    add_element(curr, A[i]);
    R[i - m] = curr;
  }
  for (Query q : q0) {
    vector<int> M = oper(L[q.l - l], R[q.r - 1 - m]);
    int res = 0;
    for (int v : M)
      if ((res ^ v) > res) res ^= v;
    ans[q.id] = res;
  }
}
int main() {
  while (scanf("%d", &n) >= 1) {
    for (int i = (0); i < (int)(n); i++) scanf("%d", &A[i]);
    scanf("%d", &q);
    Q.resize(q);
    for (int z = (0); z < (int)(q); z++) Q[z].in(z);
    solve(0, n, Q);
    for (int z = (0); z < (int)(q); z++) {
      printf("%d\n", ans[z]);
    }
  }
  return 0;
}
