#include <bits/stdc++.h>
using namespace std;
int n, a[500005], ans[500005];
int q, ql[500005], qr[500005];
vector<int> G[500005];
int cnt;
int b[30];
int tim[30];
void ins(int x, int t) {
  for (int i = 29; i >= 0; i--)
    if (x >> i & 1) {
      if (b[i]) {
        if (t < tim[i])
          x ^= b[i];
        else
          swap(x, b[i]), swap(tim[i], t), x ^= b[i];
      } else
        b[i] = x, x = 0, tim[i] = t, cnt++;
    }
}
int qry(int x, int t) {
  for (int i = 29; i >= 0; i--)
    if (tim[i] >= t && (x ^ b[i]) > x) x ^= b[i];
  return x;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++)
    scanf("%d%d", &ql[i], &qr[i]), G[qr[i]].push_back(i);
  for (int i = 1; i <= n; i++) {
    ins(a[i], i);
    for (int j = 0; j < G[i].size(); j++) ans[G[i][j]] = qry(0, ql[G[i][j]]);
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
}
