#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
  if (a < b) a = b;
}
int N, Q;
int arr[500013];
vector<pair<int, int> > query[500013];
int ans[500013];
vector<pair<int, int> > basis;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(12);
  cerr << fixed << setprecision(4);
  cin >> N;
  for (auto i = (0); i < (N); i++) {
    cin >> arr[i];
  }
  cin >> Q;
  for (auto i = (0); i < (Q); i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    query[l].push_back({r, i});
  }
  for (auto i = (N)-1; i >= (0); i--) {
    int x = arr[i];
    basis.push_back({x, i});
    for (auto j = (((int)((basis).size()))) - 1; j >= (0); j--) {
      int x = basis[j].first;
      for (auto k = (j + 1); k < (((int)((basis).size()))); k++) {
        ckmin(x, x ^ basis[k].first);
      }
      if (x == 0) {
        basis.erase(basis.begin() + j);
      } else {
        basis[j].first = x;
      }
    }
    for (pair<int, int> p : query[i]) {
      int qid = p.second, r = p.first;
      int res = 0;
      vector<int> lol;
      for (auto j = (((int)((basis).size()))) - 1; j >= (0); j--) {
        if (basis[j].second > r) break;
        lol.push_back(basis[j].first);
      }
      sort((lol).begin(), (lol).end(), greater<int>());
      for (auto j = (1); j < (((int)((lol).size()))); j++) {
        int x = lol[j];
        for (auto k = (0); k < (j); k++) {
          ckmin(x, x ^ lol[k]);
        }
        lol[j] = x;
      }
      for (int v : lol) {
        ckmax(res, res ^ v);
      }
      ans[qid] = res;
    }
  }
  for (auto i = (0); i < (Q); i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
