#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int w = 0, x = 0;
  char c = getchar();
  while (!isdigit(c)) w |= c == '-', c = getchar();
  while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar();
  return w ? -x : x;
}
namespace star {
const int maxn = 5e5 + 10;
int n, m;
struct Base {
  int c[35], id[35];
  inline void clear() { memset(c, 0, sizeof c); }
  inline void insert(int x, int p) {
    for (int i = 31; ~i; i--)
      if (x & (1 << i)) {
        if (c[i])
          p > id[i] && (swap(id[i], p), swap(x, c[i]), 0), x ^= c[i];
        else {
          c[i] = x;
          id[i] = p;
          return;
        }
      }
  }
  inline int query(int p) {
    int w = 0;
    for (int i = 31; ~i; i--)
      if (id[i] >= p and (w ^ c[i]) > w) w ^= c[i];
    return w;
  }
} e[maxn];
inline void work() {
  n = read();
  for (int i = 1; i <= n; i++) e[i] = e[i - 1], e[i].insert(read(), i);
  m = read();
  while (m--) {
    int l = read(), r = read();
    printf("%d\n", e[r].query(l));
  }
}
}  // namespace star
signed main() {
  star::work();
  return 0;
}
