#include <bits/stdc++.h>
using namespace std;
int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ '0'), ch = getchar();
  return x;
}
const int N = 5e5 + 5;
int n, q, a[N], ans[N];
struct ND {
  int r, id;
  ND(int _r = 0, int _id = 0) { r = _r, id = _id; }
};
struct Q {
  int l, r, id;
  Q(int _l = 0, int _r = 0, int _id = 0) { l = _l, r = _r, id = _id; }
};
bool cmp(ND p, ND q) { return p.r < q.r; }
vector<ND> qr[N];
struct Bas {
  int d[20];
  void csh() { memset(d, 0, sizeof(d)); }
} d[N];
Bas insrt(Bas p, int x) {
  for (int i = 19; i >= 0; i--)
    if (x & 1 << i)
      if (p.d[i])
        x ^= p.d[i];
      else {
        p.d[i] = x;
        break;
      }
  return p;
}
Bas merge(Bas x, Bas y) {
  for (int i = 19; i >= 0; i--)
    if (y.d[i]) x = insrt(x, y.d[i]);
  return x;
}
int fdmax(Bas x) {
  int maxn = 0;
  for (int i = 19; i >= 0; i--)
    if ((maxn ^ x.d[i]) >= maxn) maxn = maxn ^ x.d[i];
  return maxn;
}
vector<Q> qry[N << 2];
void prework(int l, int r, int o) {
  if (l == r) {
    for (vector<ND>::iterator it = qr[l].begin();
         it != qr[l].end() && it->r == r; it++)
      qry[o].push_back(Q(l, it->r, it->id));
    return;
  }
  int mid = l + r >> 1;
  prework(l, mid, o << 1), prework(mid + 1, r, o << 1 | 1);
  for (int i = l; i <= mid; i++)
    for (vector<ND>::iterator it =
             lower_bound(qr[i].begin(), qr[i].end(), ND(mid + 1, 0), cmp);
         it != qr[i].end() && it->r <= r; it++)
      qry[o].push_back(Q(i, it->r, it->id));
}
void solve(int l, int r, int o) {
  if (l == r) {
    for (vector<Q>::iterator it = qry[o].begin(); it != qry[o].end(); it++)
      ans[it->id] = a[l];
    return;
  }
  int mid = l + r >> 1;
  solve(l, mid, o << 1), solve(mid + 1, r, o << 1 | 1);
  d[mid].csh(), d[mid + 1].csh();
  d[mid] = insrt(d[mid], a[mid]), d[mid + 1] = insrt(d[mid + 1], a[mid + 1]);
  for (int i = mid - 1; i >= l; i--) d[i] = insrt(d[i + 1], a[i]);
  for (int i = mid + 2; i <= r; i++) d[i] = insrt(d[i - 1], a[i]);
  for (vector<Q>::iterator it = qry[o].begin(); it != qry[o].end(); it++)
    ans[it->id] = fdmax(merge(d[it->l], d[it->r]));
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  q = read();
  for (int i = 1; i <= q; i++) {
    int l = read(), r = read();
    qr[l].push_back(ND(r, i));
  }
  for (int i = 1; i <= n; i++) sort(qr[i].begin(), qr[i].end(), cmp);
  prework(1, n, 1);
  solve(1, n, 1);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
