#include <bits/stdc++.h>
using namespace std;
template <typename num_t>
inline void add_mod(num_t& a, const long long& b, const int& m) {
  a = (a + b) % m;
  if (a < 0) a += m;
}
template <typename num_t>
inline bool update_max(num_t& a, const num_t& b) {
  return a < b ? a = b, true : false;
}
template <typename num_t>
inline bool update_min(num_t& a, const num_t& b) {
  return a > b ? a = b, true : false;
}
template <typename num_t>
num_t gcd(num_t lhs, num_t rhs) {
  return !lhs ? rhs : gcd(rhs % lhs, lhs);
}
template <typename num_t>
num_t pw(num_t n, num_t k, num_t mod) {
  num_t res = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) res = 1ll * res * n % mod;
    n = 1ll * n * n % mod;
  }
  return res;
}
const int inf = 1e9 + 7;
const int mod = inf;
const long long ll_inf = 9ll * inf * inf;
const int MAX_N = 5e5 + 7;
const int M = 20;
int first_bit[1 << M];
void init() {
  first_bit[0] = -1;
  for (int i = (1), _b = (1 << M); i < _b; ++i) {
    if (i & (i - 1))
      first_bit[i] = first_bit[i - 1];
    else
      first_bit[i] = first_bit[i - 1] + 1;
  }
}
struct matrix {
  int arr[M];
  int mask = 0;
  int left_index = 0;
  bool changed = false;
  int max_value = 0;
  matrix(int idx) {
    left_index = idx;
    fill_n(arr, M, 0);
  }
  void add_row(int x) {
    while (x > 0) {
      int c = first_bit[x];
      if (arr[c] == 0) {
        arr[c] = x;
        mask |= 1 << c;
        c = 0;
        changed = true;
      } else
        x ^= arr[c];
    }
  }
  int get_max() {
    if (!changed) return max_value;
    int res = 0;
    for (int i = M - 1; i >= 0; --i)
      if (arr[i] && (res ^ arr[i]) > res) {
        res ^= arr[i];
      }
    changed = false;
    return max_value = res;
  }
};
int n;
int a[MAX_N];
struct query {
  int left, right;
};
vector<int> closed[MAX_N];
vector<query> queries;
vector<matrix> data;
int ans[MAX_N];
void solve() {
  init();
  cin >> n;
  for (int i = (0), _b = (n); i < _b; ++i) cin >> a[i];
  int q;
  cin >> q;
  queries.resize(q);
  for (int i = (0), _b = (q); i < _b; ++i) {
    cin >> queries[i].left >> queries[i].right;
    --queries[i].left;
    --queries[i].right;
    closed[queries[i].right].push_back(i);
  }
  for (int i = (0), _b = (n); i < _b; ++i) {
    data.push_back(matrix(i));
    vector<matrix> new_data;
    for (auto& mtx : data) {
      mtx.add_row(a[i]);
      if (new_data.empty() || new_data.back().mask != mtx.mask) {
        new_data.push_back(mtx);
      }
    }
    data = new_data;
    for (int id : closed[i]) {
      int j = 0;
      while (j + 1 < data.size() && data[j + 1].left_index <= queries[id].left)
        ++j;
      ans[id] = data[j].get_max();
    }
  }
  for (int j = (0), _b = (q); j < _b; ++j) cout << ans[j] << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  const bool multiple_test = false;
  int test = 1;
  if (multiple_test) cin >> test;
  for (int i = 0; i < test; ++i) {
    solve();
  }
}
