#include <bits/stdc++.h>
using namespace std;
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <class T>
inline bool read(T &x) {
  int c = getchar();
  int sgn = 1;
  while (~c && c < '0' || c > '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}
const int INF = 2000000009;
const int MX = 500005;
const double EPS = 1e-9;
const int MOD = 1000000007;
template <typename T>
struct Basis {
  int n;
  T *a;
  Basis(int n = 20) : n(n) { a = new T[n](); }
  ~Basis() { delete[] a; }
  void insert(T x) {
    for (int i = n - 1; ~i; i--) {
      if (a[i] == 0) a[i] = x;
      x = min(x, x ^ a[i]);
    }
  }
  T getMaxXor(T x = 0) {
    for (int i = n - 1; ~i; i--) x = max(x, x ^ a[i]);
    return x;
  }
  T getMinXor(T x = 0) {
    for (int i = n - 1; ~i; i--) x = min(x, x ^ a[i]);
    return x;
  }
  bool canMake(T x) { return getMinXor(x) == 0; }
  int size() {
    int x = 0;
    for (int i = 0; i < n; i++)
      if (a[i]) x++;
    return x;
  }
};
Basis<int> tree[3 * MX];
int c[MX];
void merge(Basis<int> &a, Basis<int> &b) {
  for (int i = b.n - 1; ~i; i--) {
    if (b.a[i]) a.insert(b.a[i]);
  }
}
void update(int node, int l, int r, int pos) {
  if (r < pos || l > pos) return;
  tree[node].insert(c[pos]);
  if (l == r) return;
  int mid = l + r >> 1;
  update(node << 1, l, mid, pos);
  update(node << 1 | 1, mid + 1, r, pos);
}
void query(int node, int l, int r, int i, int j, Basis<int> &b) {
  if (l > j || r < i) return;
  if (l >= i && r <= j) {
    if (r - l < 20) {
      while (l <= r) b.insert(c[l++]);
      return;
    }
    merge(b, tree[node]);
    return;
  }
  int mid = l + r >> 1;
  query(node << 1, l, mid, i, j, b);
  query(node << 1 | 1, mid + 1, r, i, j, b);
}
int main() {
  int n = ({
    int a;
    read(a);
    a;
  });
  for (int i = 1; i <= n; i++) {
    c[i] = ({
      int a;
      read(a);
      a;
    });
    update(1, 1, n, i);
  }
  int q = ({
    int a;
    read(a);
    a;
  });
  while (q--) {
    int l = ({
      int a;
      read(a);
      a;
    }),
        r = ({
          int a;
          read(a);
          a;
        });
    Basis<int> b;
    query(1, 1, n, l, r, b);
    printf("%d\n", b.getMaxXor());
  }
  return 0;
}
