#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) { return n | (1LL << i); }
inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }
int dx[] = {0, 0, +1, -1, +1, +1, -1, -1};
int dy[] = {+1, -1, 0, 0, +1, -1, +1, -1};
template <typename first, typename second>
ostream &operator<<(ostream &os, const pair<first, second> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}
template <typename first, typename second>
ostream &operator<<(ostream &os, const map<first, second> &v) {
  os << "[";
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << ", ";
    os << it->first << " = " << it->second;
  }
  return os << "]";
}
void faltu() { cerr << '\n'; }
template <typename T>
void faltu(T a[], int n) {
  for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
  cerr << '\n';
}
template <typename T, typename... hello>
void faltu(T arg, const hello &...rest) {
  cerr << arg << ' ';
  faltu(rest...);
}
inline int max(int a, int b) { return (a > b) ? a : b; }
struct xorSpaces {
  int Rank, dim;
  array<int, 20> basis;
  xorSpaces() {
    Rank = 0, dim = 20;
    fill((basis).begin(), (basis).end(), 0);
  }
  void addBasis(int n) {
    for (int i = dim - 1; i >= 0; i--) {
      if (n & (1 << i)) {
        if (basis[i] == 0) {
          basis[i] = n;
          Rank++;
          break;
        } else {
          n ^= basis[i];
        }
      }
    }
  }
  xorSpaces operator+=(xorSpaces other) {
    if (other.Rank == 0) return other;
    if (Rank == 0) {
      return *this = other;
    }
    for (int i = dim - 1; i >= 0; i--) {
      if (other.basis[i]) addBasis(other.basis[i]);
    }
    return *this;
  }
  int getMax() {
    int ans = 0;
    for (int i = dim - 1; i >= 0; i--) {
      if (basis[i] and (ans & (1 << i)) == 0) ans ^= basis[i];
    }
    return ans;
  }
};
const int mx = 5e5 + 123;
xorSpaces table[(mx / 20) + 123][23], s[mx], p[mx];
int a[mx];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, l, r, q;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int d = (n) / 20;
  for (int i = 0; i < n; i++) {
    if (i % 20) p[i] = p[i - 1];
    p[i].addBasis(a[i]);
  }
  for (int i = n - 1; i >= 0; i--) {
    if (i % 20 != 19) s[i] = s[i + 1];
    s[i].addBasis(a[i]);
  }
  for (int i = 0; i <= d; i++) {
    table[i][0] = s[i * 20];
  }
  for (int i = 1; i <= 15; i++) {
    for (int j = 0; j + (1 << (i - 1)) <= d; j++) {
      table[j][i] = table[j][i - 1];
      table[j][i] += (table[j + (1 << (i - 1))][i - 1]);
    }
  }
  cin >> q;
  while (q--) {
    cin >> l >> r;
    l--, r--;
    int block_l = l / 20, block_r = r / 20;
    xorSpaces ans;
    if (block_l == block_r) {
      for (int i = l; i <= r; i++) {
        ans.addBasis(a[i]);
      }
    } else {
      ans += (s[l]);
      ans += (p[r]);
      block_l++, block_r--;
      if (block_l <= block_r) {
        r = block_r, l = block_l;
        int lg = log2(r - l + 1);
        ans += (table[l][lg]);
        ans += (table[r - (1 << lg) + 1][lg]);
      }
    }
    cout << ans.getMax() << "\n";
  }
  return 0;
}
