#include <bits/stdc++.h>
using namespace std;
const int A = 20;
struct LB {
  LB() : sz(0) { memset(basis, 0, sizeof(basis)); }
  bool add(int num) {
    if (num == 0 || sz == A) {
      return false;
    }
    for (int i = 0; i < sz; ++i) {
      num = min(num, num ^ basis[i]);
    }
    if (num == 0) {
      return false;
    }
    basis[sz++] = num;
    for (int i = sz - 1; i > 0; --i) {
      if (basis[i] > basis[i - 1]) {
        swap(basis[i], basis[i - 1]);
      } else {
        break;
      }
    }
    return true;
  }
  int maxNum() {
    int res = 0;
    for (int i = 0; i < sz; ++i) {
      res = max(res, res ^ basis[i]);
    }
    return res;
  }
  int size() const { return sz; }
  LB merge(const LB& other) const {
    LB res = *this;
    for (int i = 0; i < other.size(); ++i) {
      res.add(other.basis[i]);
    }
    return res;
  }
  int sz;
  int basis[A];
};
class Solution {
 public:
  vector<int> answer(vector<int>& nums, vector<pair<int, int>>& qs) {
    int n = nums.size();
    int m = qs.size();
    vector<int> res(m, 0);
    vector<LB> prefix(n);
    vector<LB> suffix(n);
    for (int i = 0; i < n; ++i) {
      if (nums[i] == 0) {
        continue;
      }
      prefix[i].add(nums[i]);
      suffix[i] = prefix[i];
    }
    vector<int> qids(m, 0);
    iota(qids.begin(), qids.end(), 0);
    solve(0, n, nums, prefix, suffix, qids, qs, res);
    return res;
  }
  void solve(int l, int r, vector<int>& nums, vector<LB>& prefix,
             vector<LB>& suffix, vector<int>& qids, vector<pair<int, int>>& qs,
             vector<int>& res) {
    if (l >= r) {
      return;
    }
    if (l + 1 == r) {
      for (auto q : qids) {
        res[q] = nums[l];
      }
      return;
    }
    int m = l + (r - l) / 2;
    vector<int> lqids, rqids;
    vector<int> mqids;
    for (auto q : qids) {
      if (qs[q].second < m) {
        lqids.push_back(q);
      } else if (qs[q].first >= m) {
        rqids.push_back(q);
      } else {
        mqids.push_back(q);
      }
    }
    solve(l, m, nums, prefix, suffix, lqids, qs, res);
    solve(m, r, nums, prefix, suffix, rqids, qs, res);
    for (auto q : mqids) {
      int ll = qs[q].first;
      int rr = qs[q].second;
      res[q] = suffix[ll].merge(prefix[rr]).maxNum();
    }
    for (int i = m; i < r; ++i) {
      prefix[i] = prefix[i - 1];
      prefix[i].add(nums[i]);
    }
    for (int i = m; i > l; --i) {
      suffix[i - 1] = suffix[i];
      suffix[i - 1].add(nums[i - 1]);
    }
  }
};
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  Solution sol;
  int n;
  cin >> n;
  vector<int> nums(n);
  for (int i = 0; i < n; ++i) {
    cin >> nums[i];
  }
  int q;
  cin >> q;
  vector<pair<int, int>> qs;
  qs.reserve(q);
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    qs.emplace_back(l - 1, r - 1);
  }
  auto res = sol.answer(nums, qs);
  for (auto r : res) {
    cout << r << endl;
  }
  return 0;
}
