#include <bits/stdc++.h>
long long gi() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
std::mt19937 rnd(time(NULL));
template <class T>
void cxk(T& a, T b) {
  a = a > b ? a : b;
}
template <class T>
void cnk(T& a, T b) {
  a = a < b ? a : b;
}
int p[20], pos[20];
int a[500010], cnt;
int ql[500010], qr[500010], ans[500010];
std::vector<int> G[500010];
int main() {
  int n = gi();
  for (int i = 1; i <= n; ++i) a[i] = gi();
  int q = gi(), l, r;
  for (int i = 1; i <= q; ++i) {
    ql[i] = l = gi(), qr[i] = r = gi();
    G[qr[i]].push_back(i);
  }
  for (int s = 1, x; s <= n; ++s) {
    x = a[s];
    int np = s;
    for (int i = 19; ~i; --i)
      if (x >> i & 1) {
        if (!p[i]) {
          p[i] = x, pos[i] = np;
          break;
        }
        if (np > pos[i]) std::swap(pos[i], np), std::swap(x, p[i]);
        x ^= p[i];
      }
    for (int i : G[s])
      for (int j = 19; ~j; --j)
        if (pos[j] >= ql[i] && ans[i] < (ans[i] ^ p[j])) ans[i] ^= p[j];
  }
  for (int i = 1; i <= q; ++i) printf("%d\n", ans[i]);
  return 0;
}
