#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 233;
vector<int> q[maxn * 4], s[maxn];
int l[maxn], r[maxn], c[maxn];
int L[maxn][21], a[21], ans[maxn], t[21];
int first[1000001];
inline void add(int x) {
  while (x && a[first[x]]) {
    x ^= a[first[x]];
  }
  if (!x) return;
  a[first[x]] = x;
}
inline int merge(int x) {
  for (int i = 20; i >= 0; i--) add(L[x][i]);
  int ans = 0;
  for (int i = 20; i >= 0; i--)
    if (a[i] && !(ans & (1 << i))) {
      ans ^= a[i];
    }
  return ans;
}
void divide(int _l, int _r, int cur) {
  if (_l > _r) return;
  if (_l == _r) {
    for (int j = 0; j < q[cur].size(); j++) ans[q[cur][j]] = c[_l];
    return;
  }
  int mid = (_l + _r) >> 1, lc = cur << 1, rc = lc | 1;
  for (int j = 0; j < q[cur].size(); j++) {
    int x = q[cur][j];
    if (r[x] < mid) q[lc].push_back(x);
    if (l[x] > mid) q[rc].push_back(x);
  }
  divide(_l, mid - 1, lc);
  divide(mid + 1, _r, rc);
  for (int j = 0; j < q[cur].size(); j++) {
    int x = q[cur][j];
    if (r[x] < mid) continue;
    if (l[x] > mid) continue;
    s[r[x]].push_back(x);
  }
  memset(a, 0, sizeof(a));
  for (int i = mid - 1; i >= _l; i--) {
    add(c[i]);
    memcpy(L[i], a, sizeof(a));
  }
  memset(a, 0, sizeof(a));
  for (int i = mid; i <= _r; i++) {
    add(c[i]);
    for (int j = 0; j < s[i].size(); j++) {
      int x = s[i][j];
      memcpy(t, a, sizeof(a));
      ans[x] = merge(l[x]);
      memcpy(a, t, sizeof(t));
    }
    s[i].clear();
  }
}
int main() {
  for (int i = 1; i <= 1000000; i++) {
    for (int j = 20; j >= 0; j--)
      if (i & (1 << j)) {
        first[i] = j;
        break;
      }
  }
  int n, Q;
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  cin >> Q;
  for (int i = 1; i <= Q; i++) {
    scanf("%d%d", &l[i], &r[i]);
    q[1].push_back(i);
  }
  divide(1, n, 1);
  for (int i = 1; i <= Q; i++) printf("%d\n", ans[i]);
  return 0;
}
