#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T read() {
  T f = 0, x = 0;
  char c = getchar();
  while (!isdigit(c)) f = c == '-', c = getchar();
  while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
  return f ? -x : x;
}
namespace run {
const int N = 5e5 + 9;
int n, a[N], Q, ans[N], pos[64];
vector<pair<int, int> > ask[N];
int main() {
  n = read<int>();
  for (int i = 1; i <= n; i++) a[i] = read<int>();
  Q = read<int>();
  for (int i = 1; i <= Q; i++) {
    int l = read<int>(), r = read<int>();
    ask[r].push_back(pair<int, int>(l, i));
  }
  for (int i = 1; i <= n; i++) {
    int rak = a[i] ? (32 - __builtin_clz(a[i])) : 0, tmp = i, tot = 0;
    while (rak) {
      int pre = pos[rak];
      if (!pre) {
        pos[rak] = tmp;
        break;
      }
      if (pre < tmp) {
        a[pre] ^= a[tmp], pos[rak] = tmp;
        rak = a[pre] ? (32 - __builtin_clz(a[pre])) : 0, tmp = pre;
      } else {
        a[tmp] ^= a[pre];
        rak = a[tmp] ? (32 - __builtin_clz(a[tmp])) : 0;
      }
    }
    for (int j = 0; j < ask[i].size(); j++) {
      int now = 0;
      for (int k = 22; k; k--)
        if (pos[k] >= ask[i][j].first && ~now >> (k - 1) & 1) now ^= a[pos[k]];
      ans[ask[i][j].second] = now;
    }
  }
  for (int i = 1; i <= Q; i++) printf("%d\n", ans[i]);
  return 0;
}
}  // namespace run
int main() { return run::main(); }
