#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int base[65];
int p[65];
int cnt;
int a[maxn];
struct node {
  int l, r;
  int id;
} e[maxn];
bool cmp(node a, node b) { return a.r < b.r; }
void Insert(int pos, int x) {
  for (int i = 20; i >= 0; i--) {
    if (x & (1 << i)) {
      if (!base[i]) {
        base[i] = x;
        p[i] = pos;
        return;
      } else if (pos > p[i]) {
        swap(pos, p[i]);
        swap(x, base[i]);
      }
      x ^= base[i];
    }
  }
}
int getMax(int k) {
  int ans = 0;
  int l = e[k].l, r = e[k].r;
  for (int i = 20; i >= 0; i--)
    if (p[i] >= l && p[i] <= r) ans = max(ans, base[i] ^ ans);
  return ans;
}
int ans[maxn];
int main() {
  int n, m;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &e[i].l, &e[i].r);
    e[i].id = i;
  }
  sort(e + 1, e + m + 1, cmp);
  int k = 1;
  for (int i = 1; i <= n; i++) {
    Insert(i, a[i]);
    while (i == e[k].r) {
      ans[e[k].id] = getMax(k);
      k++;
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
}
