#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mxn = 500033;
const int mod = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) f = c == '-' ? -1 : 1, c = getchar();
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return x * f;
}
inline long long gcd(long long a, long long b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long ksm(long long a, long long b, long long mod) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}
long long inv2(long long a, long long mod) { return ksm(a, mod - 2, mod); }
void exgcd(long long a, long long b, long long &x, long long &y, long long &d) {
  if (!b) {
    d = a;
    x = 1;
    y = 0;
  } else {
    exgcd(b, a % b, y, x, d);
    y -= x * (a / b);
  }
}
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int n, q, a[mxn], bs[30], pos[30], res[mxn];
struct node {
  int l, r, id;
  bool operator<(const node &d) const { return r < d.r; }
} qy[mxn];
void insert(int x, int id) {
  for (int i = 20; i >= 0; --i) {
    if ((x >> i) & 1) {
      if (!bs[i]) {
        bs[i] = x;
        pos[i] = id;
        break;
      }
      if (pos[i] < id) {
        swap(pos[i], id);
        swap(x, bs[i]);
      }
      x ^= bs[i];
    }
  }
}
int run(int lim) {
  int res = 0;
  for (int i = 20; i >= 0; --i)
    if (pos[i] >= lim && res < (res ^ bs[i])) res = res ^ bs[i];
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  std::cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    cin >> qy[i].l >> qy[i].r;
    qy[i].id = i;
  }
  sort(qy + 1, qy + q + 1);
  int cur = 0;
  for (int i = 1; i <= q; ++i) {
    while (cur < qy[i].r) {
      cur++;
      insert(a[cur], cur);
    }
    res[qy[i].id] = run(qy[i].l);
  }
  for (int i = 1; i <= q; ++i) cout << res[i] << endl;
  return 0;
}
