#include <bits/stdc++.h>
using namespace std;
int burger[500005], n, q, x, y;
vector<pair<int, int> > interval[500005];
int val[500005], p[500005];
int ans[500005];
void add(int h, int pos) {
  for (int i = 19; ~i; i--)
    if (((1 << i) & h) != 0) {
      if (val[i] == 0) {
        val[i] = h;
        p[i] = pos;
        break;
      }
      if (p[i] < pos) {
        swap(p[i], pos);
        swap(val[i], h);
      }
      h ^= val[i];
    }
}
int get_ans(int pos) {
  int sol = 0;
  for (int i = 19; ~i; i--)
    if (p[i] >= pos) sol = max(sol, sol ^ val[i]);
  return sol;
}
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout.sync_with_stdio(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> burger[i];
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> x >> y;
    interval[y].push_back({x, i});
  }
  for (int i = 1; i <= n; i++) {
    add(burger[i], i);
    for (int j = 0; j < interval[i].size(); j++)
      ans[interval[i][j].second] = get_ans(interval[i][j].first);
  }
  for (int i = 1; i <= q; i++) cout << ans[i] << " ";
  return 0;
}
