#include <bits/stdc++.h>
using namespace std;
struct node {
  int l, r, id;
  bool operator<(const node& a) const { return r < a.r; }
} dou[600010];
inline int read() {
  int x;
  scanf("%d", &x);
  return x;
}
int a[600010], pos[600010], init[600010], n, m, ans[600010];
inline void add(int x, int whe) {
  for (int i = 20; i >= 0; --i) {
    if ((x >> i) & 1) {
      if (!a[i]) {
        a[i] = x;
        pos[i] = whe;
        break;
      } else if (pos[i] < whe) {
        swap(pos[i], whe);
        swap(a[i], x);
      }
      x ^= a[i];
    }
  }
}
inline int get_ans(int x, int whe) {
  for (int i = 20; i >= 0; --i)
    if (whe <= pos[i] && (x ^ a[i]) > x) x ^= a[i];
  return x;
}
int main() {
  int now = 0;
  n = read();
  for (int i = 1; i <= n; ++i) init[i] = read();
  m = read();
  for (int x, y, i = 1; i <= m; ++i)
    x = read(), y = read(), dou[i] = (node){x, y, i};
  sort(dou + 1, dou + 1 + m);
  for (int i = 1; i <= m; ++i) {
    while (now < dou[i].r) now++, add(init[now], now);
    ans[dou[i].id] = get_ans(0, dou[i].l);
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
}
