#include <bits/stdc++.h>
inline int inp() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while (c >= '0' && c <= '9') {
    sum = sum * 10 + c - '0';
    c = getchar();
  }
  return sum;
}
int have[1000010];
struct Base {
  int f[50];
  int pos[50];
  void init() { memset(f, -1, sizeof(f)); }
  void insert(int x, int pc) {
    for (int i = 20; i >= 0; i--) {
      if (x & (1 << i)) {
        if (f[i] == -1) {
          f[i] = x;
          pos[i] = pc;
          return;
        }
        if (pc > pos[i]) {
          std::swap(f[i], x);
          std::swap(pos[i], pc);
        }
        x ^= f[i];
      }
    }
  }
  int query(int l) {
    int ans = 0;
    for (int i = 20; i >= 0; i--) {
      if ((f[i] != -1) && (pos[i] >= l) && ((ans ^ f[i]) > ans)) ans ^= f[i];
    }
    return ans;
  }
} wxwak;
struct Node {
  int l;
  int r;
  int k;
} s[500010];
int a[500010], ans[500010];
bool cmp(Node a, Node b) { return a.r < b.r; }
int main() {
  wxwak.init();
  int n = inp();
  for (int i = 1; i <= n; i++) a[i] = inp();
  int m = inp();
  for (int i = 1; i <= m; i++) {
    s[i].l = inp();
    s[i].r = inp();
    s[i].k = i;
  }
  std::sort(s + 1, s + m + 1, cmp);
  int cur = 1;
  for (int i = 1; i <= n; i++) {
    wxwak.insert(a[i], i);
    while (s[cur].r == i) {
      ans[s[cur].k] = wxwak.query(s[cur].l);
      cur++;
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
}
