#include <bits/stdc++.h>
using namespace std;
int a[500002], Q, x, b[30], t[30], ans[500002], n;
inline long long rd() {
  long long x = 0;
  char c = getchar();
  bool f = 0;
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return f ? -x : x;
}
struct node {
  int l, r, id;
  bool operator<(const node &b) const { return r < b.r; }
} q[500002];
int main() {
  n = rd();
  for (int i = 1; i <= n; ++i) a[i] = rd();
  Q = rd();
  for (int i = 1; i <= Q; ++i) q[i].l = rd(), q[i].r = rd(), q[i].id = i;
  sort(q + 1, q + Q + 1);
  int p = 1;
  for (int i = 1; i <= n; ++i) {
    int tim = i;
    for (int j = 21; j >= 0; --j)
      if (a[i] & (1 << j)) {
        if (b[j]) {
          if (tim > t[j]) swap(t[j], tim), swap(a[i], b[j]);
        } else {
          b[j] = a[i];
          t[j] = tim;
          break;
        }
        a[i] ^= b[j];
      }
    while (q[p].r == i) {
      int x = 0;
      for (int j = 21; j >= 0; --j)
        if (t[j] >= q[p].l && (b[j] ^ x) > x) x ^= b[j];
      ans[q[p].id] = x;
      p++;
    }
  }
  for (int i = 1; i <= Q; ++i) printf("%d\n", ans[i]);
  return 0;
}
