#include <bits/stdc++.h>
using namespace std;
long long n, q;
long long a[500005];
long long p[70];
long long pos[70];
struct node {
  long long l, r;
  long long num;
  bool operator<(const node n1) const { return r < n1.r; }
} node[500005];
void xxj(long long x, long long p1) {
  long long temp1 = x;
  long long temp2 = p1;
  for (int i = 62; i >= 0; i--) {
    if (temp1 & (1ll * 1 << i)) {
      if (!p[i]) {
        p[i] = temp1;
        pos[i] = temp2;
        break;
      } else {
        if (pos[i] < temp2) {
          swap(p[i], temp1);
          swap(pos[i], temp2);
        }
        temp1 ^= p[i];
      }
    }
  }
  return;
}
long long query(long long l) {
  long long ans = 0;
  for (int i = 62; i >= 0; i--) {
    if (pos[i] >= l) {
      ans = max(ans, p[i] ^ ans);
    }
  }
  return ans;
}
long long res[500005];
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  scanf("%lld", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%lld%lld", &node[i].l, &node[i].r);
    node[i].num = i;
  }
  sort(node + 1, node + q + 1);
  long long now = 0;
  for (int i = 1; i <= q; i++) {
    while (now < node[i].r) {
      now++;
      xxj(a[now], now);
    }
    res[node[i].num] = query(node[i].l);
  }
  for (int i = 1; i <= q; i++) {
    cout << res[i] << endl;
  }
}
