#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int a[N];
struct query {
  int id, l, r;
} q[N], rep[N];
int ans[N];
struct Basis {
  int a[21];
  void clear() { memset(a, 0, sizeof(a)); }
  void insert(int x) {
    for (int i = 20; i >= 0; --i) {
      if (((x >> i) & 1) == 0) continue;
      if (a[i]) {
        x ^= a[i];
        continue;
      }
      for (int j = i - 1; j >= 0; --j) {
        if (((x >> j) & 1) == 1) {
          x ^= a[j];
        }
      }
      for (int j = i + 1; j <= 20; ++j) {
        if (((a[j] >> i) & 1) == 1) {
          a[j] ^= x;
        }
      }
      a[i] = x;
      return;
    }
  }
  int query() {
    int ans = 0;
    for (int i = 0; i <= 20; ++i) {
      ans ^= a[i];
    }
    return ans;
  }
} suf[N], pre[N];
Basis merge(const Basis &A, const Basis &B) {
  Basis C = A;
  for (int i = 0; i <= 20; ++i) {
    if (B.a[i]) {
      C.insert(B.a[i]);
    }
  }
  return C;
}
void solve(int l, int r, int ql, int qr) {
  if (l == r) {
    for (int i = ql; i <= qr; ++i) {
      ans[q[i].id] = a[l];
    }
    return;
  }
  int mid = (l + r) >> 1;
  suf[mid].clear();
  suf[mid].insert(a[mid]);
  for (int i = mid - 1; i >= l; --i) {
    suf[i] = suf[i + 1];
    suf[i].insert(a[i]);
  }
  pre[mid + 1].clear();
  pre[mid + 1].insert(a[mid + 1]);
  for (int i = mid + 2; i <= r; ++i) {
    pre[i] = pre[i - 1];
    pre[i].insert(a[i]);
  }
  int tl = ql - 1, tr = qr + 1;
  for (int i = ql; i <= qr; ++i) {
    if (q[i].l <= mid && q[i].r > mid) {
      ans[q[i].id] = merge(suf[q[i].l], pre[q[i].r]).query();
    } else if (q[i].r <= mid) {
      rep[++tl] = q[i];
    } else {
      rep[--tr] = q[i];
    }
  }
  for (int i = ql; i <= tl; ++i) {
    q[i] = rep[i];
  }
  for (int i = tr; i <= qr; ++i) {
    q[i] = rep[i];
  }
  solve(l, mid, ql, tl);
  solve(mid + 1, r, tr, qr);
}
int main() {
  int n, m;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    q[i].id = i;
    scanf("%d%d", &q[i].l, &q[i].r);
  }
  solve(1, n, 1, m);
  for (int i = 1; i <= m; ++i) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
