#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cassert>

const int kMaxCBits = 21;
const int kMaxC = 1000010;
const int kMaxN = 524288;

// holds linearly independent vectors
// invariant: i-th vector has i-th leading bit, and no other vectors have this
// bit set.
struct Set {
  Set() : has_vector_mask(0) {}

  static int leading_bit(int x) {
    assert(x > 0);
    return x == 1 ? 0 : 1 + leading_bit(x / 2);
  }

  static bool has_bit(int x, int c) {
    return !!(x & (1 << c));
  }

  int has_vector(int c) const {
    return has_bit(has_vector_mask, c);
  }

  // O(kMaxCBits)
  void add(int x) {
    assert(x < kMaxC);

    // If I know how to get all bits of x, I can stop.
    if ((has_vector_mask | x) == has_vector_mask) {
      return;
    }

    // Remove all bits that we already know how to get.
    while ((has_vector_mask & x)) {
      int intersection = (has_vector_mask & x);
      x ^= vectors[leading_bit(intersection)];
    }
    if (!x) {
      return;
    }

    int lead_x = leading_bit(x);
    assert(lead_x < kMaxCBits);
    assert(!has_vector(lead_x));

    vectors[lead_x] = x;
    has_vector_mask |= (1 << lead_x);

    // Vectors above me shouldn't have this bit set.
    // Vectors below me can't have this bit set because their leading bit
    // is below.
    for (int i = lead_x + 1; i < kMaxCBits; ++i) {
      if (has_vector(i) && has_bit(vectors[i], lead_x)) {
        vectors[i] ^= x;
      }
    }
  }

  // O(kMaxCBits ^ 2)
  void test_invariants() const {
    for (int i = kMaxCBits - 1; i >= 0; --i) {
      if (!has_vector(i)) {
        continue;
      }
      printf("%2d: ", i);
      for (int j = kMaxCBits - 1; j >= 0; --j) {
        printf("%d", (has_bit(vectors[i], j)));
      }
      printf("\n");
    }
    int max = get_max();
    printf("xx: ");
    for (int j = kMaxCBits - 1; j >= 0; --j) {
      printf("%d", (has_bit(max, j)));
    }
    printf("\n");

    for (int i = 0; i < kMaxCBits; ++i) {
      if (!has_vector(i)) {
        continue;
      }
      assert(leading_bit(vectors[i]) == i);
      for (int j = 0; j < kMaxCBits; ++j) {
        if (i == j || !has_vector(j)) {
          continue;
        }
        assert(!has_bit(vectors[j], i));
      }
    }
  }

  // O(kMaxCBits)
  // returns the max Xor that we can get from this set.
  int get_max() const {
    int sol = 0;
    for (int i = kMaxCBits - 1; i >= 0; --i) {
      if (has_vector(i)) {
        assert(has_bit(vectors[i], i));
        if (!has_bit(sol, i)) {
          sol ^= vectors[i];
        }
      }
    }
    return sol;
  }

  int vectors[kMaxCBits];
  int has_vector_mask;
};

Set tournament[kMaxN * 2];

void load() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int c;
    scanf("%d", &c);
    tournament[kMaxN + i].add(c);
  }
}

void merge(const Set& lhs, const Set& rhs, Set *result) {
  if (!lhs.has_vector_mask && !rhs.has_vector_mask) {
    return;
  }
  *result = lhs;
  for (int i = 0; i < kMaxCBits; ++i) {
    if (rhs.has_vector(i)) {
      result->add(rhs.vectors[i]);
    }
  }
}

void build() {
  for (int i = kMaxN - 1; i > 0; --i) {
    merge(tournament[i * 2], tournament[i * 2 + 1], &tournament[i]);
  }
}

struct Interval {
  int lo, hi;
  Interval(int lo, int hi) : lo(lo), hi(hi) {
    if (hi < lo) {
      hi = lo;
    }
  }

  Interval split_lo() const { return Interval(lo, (lo + hi) / 2); }
  Interval split_hi() const { return Interval((lo + hi) / 2, hi); }
  bool contains(int x) const { return x >= lo && x < hi; }

  int size() const { return hi - lo; }
  Interval intersection(const Interval& other) const {
    return Interval(std::max(lo, other.lo), std::min(hi, other.hi));
  }
  bool contains(const Interval& other) const {
    return intersection(other).size() == other.size();
  }
  bool intersects(const Interval& other) const {
    return intersection(other).size() > 0;
  }
};

Set solve(int node, const Interval& node_interval, const Interval& query) {
  Set result;
  if (!node_interval.intersects(query)) {
    return result;
  }
  if (query.contains(node_interval)) {
    return tournament[node];
  }
  merge(
      solve(node * 2    , node_interval.split_lo(), query),
      solve(node * 2 + 1, node_interval.split_hi(), query),
      &result);
  return result;
}

Set brute(const Interval& query) {
  Set result;
  for (int i = query.lo; i < query.hi; ++i) {
    Set tmp = result;
    //tournament[kMaxN + i].test_invariants();
    //printf("\n");
    merge(tmp, tournament[kMaxN + i], &result);
  }
  //result.test_invariants();
  return result;
}

int main() {
  load();
  build();

  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int lo, hi;
    scanf("%d%d", &lo, &hi);
    Interval query(lo - 1, hi);
    int sol = solve(1, Interval(0, kMaxN), query).get_max();
    printf("%d\n", sol);
  }
  return 0;
}


// In the name of God.
// You are all thing and We're nothing.
// Ya Ali!

#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 17, lg = 20;

char c, buf[maxn * 10], *it = buf + maxn * 10 - 1;  int _x;
#define in(x)  for(x = getchar() - '0'; (c = getchar()) >= '0'; x = (x << 3) + (x << 1) + c - '0');
#define write(x)  *--it = ' ';  do{  *--it = x % 10 + '0';  }  while(x /= 10);

int n, q, cache[maxn], l[maxn], r[maxn], a[maxn];
vector<int> assign[maxn];
struct Gauss{
	int a[lg], skip;
	Gauss(){
		memset(a, 0, sizeof a);
		skip = 0;
	}
	void add(int x, int hint = lg - 1){
		for(int i = hint; i >= skip; i--)
			if(x >> i & 1)
				if(a[i])
					x ^= a[i];
				else{
					a[i] = x;
					break;
				}
		while(skip < lg && a[skip])
			skip++;
	}
	int val(){
		int ans = 0;
		for(int i = lg - 1; i >= 0; i--)
			if(ans < (ans ^ a[i]))
				ans ^= a[i];
		return ans;
	}
} ans[maxn];
Gauss operator +=(Gauss &a, const Gauss &b){
	for(int i = 0; i < lg; i++)
		if(b.a[i])
			a.add(b.a[i], i);
	return a;
}
void solve(vector<int> &q, int s = 0, int e = n - 1){
	if(e < s)
		return ;
	int mid = s + e >> 1;
	vector<int> ls, rs;
	for(auto i : q)
		if(r[i] < mid)
			ls.push_back(i);
		else if(mid < l[i])
			rs.push_back(i);
		else{
			assign[ l[i] ].push_back(i);
			assign[ r[i] ].push_back(i);
		}
	Gauss cur;
	for(int i = mid; i <= e; i++){
		cur.add(a[i]);
		for(auto qi : assign[i])
			ans[qi] += cur;
		assign[i].clear();
	}
	cur = Gauss();
	for(int i = mid; i >= s; i--){
		cur.add(a[i]);
		for(auto qi : assign[i])
			ans[qi] += cur;
		assign[i].clear();
	}
	solve(ls, s, mid - 1), solve(rs, mid + 1, e);
}
int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	scanf("%d", &q);
	vector<int> all;
	for(int i = 0; i < q; i++){
		scanf("%d%d", &l[i], &r[i]);
		l[i]--, r[i]--;
		all.push_back(i);
	}
	solve(all);
	for(int i = 0; i < q; i++)
		printf("%d\n", ans[i].val());
}


// In the name of God.
// You are all thing and We're nothing.
// Ya Ali!

#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 17, lg = 20;

char c, buf[maxn * 10], *it = buf + maxn * 10 - 1;  int _x;
#define in(x)  for(x = getchar() - '0'; (c = getchar()) >= '0'; x = (x << 3) + (x << 1) + c - '0');
#define write(x)  *--it = ' ';  do{  *--it = x % 10 + '0';  }  while(x /= 10);

int n, q, cache[maxn];
struct Gauss{
	int a[lg], skip;
	Gauss(){
		memset(a, 0, sizeof a);
		skip = 0;
	}
	void add(int x, int hint = lg - 1){
		for(int i = hint; i >= skip; i--)
			if(x >> i & 1)
				if(a[i])
					x ^= a[i];
				else{
					a[i] = x;
					break;
				}
		while(skip < lg && a[skip])
			skip++;
	}
	int val(){
		int ans = 0;
		for(int i = lg - 1; i >= 0; i--)
			if(ans < (ans ^ a[i]))
				ans ^= a[i];
		return ans;
	}
}  seg[maxn * 2];
Gauss operator +=(Gauss &a, const Gauss &b){
	for(int i = 0; i < lg; i++)
		if(b.a[i])
			a.add(b.a[i], i);
	return a;
}
int main(){
	//ios::sync_with_stdio(0), cin.tie(0);
	//cin >> n;
	//scanf("%d", &n);
	in(n);
	for(int i = 0; i < n; i++){
		int x;
		//cin >> x;
		//scanf("%d", &x);
		in(x);
		seg[n + i].add(x);
	}
	for(int i = n - 1; i > 0; i--){
		seg[i] += seg[i << 1];
		seg[i] += seg[i << 1 | 1];
	}
	//cin >> q;
	//scanf("%d", &q);
	in(q);
	for(int i = 0; i < q; i++){
		int l, r;
		//cin >> l >> r;
		//scanf("%d%d", &l, &r);
		in(l);
		in(r);
		l--;
		Gauss ans;
		for(l += n, r += n; l < r; l >>= 1, r >>= 1){
			if(l & 1)
				ans += seg[l++];
			if(r & 1)
				ans += seg[--r];
		}
		//cout << ans.val() << '\n';
		cache[i] = ans.val();
	}
	for(int i = q - 1; i >= 0; i--){
		write(cache[i]);
	}
	puts(it);
}


// In the name of God.
// You are all thing and We're nothing.
// Ya Ali!

#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 17, lg = 20;

char c, buf[maxn * 10], *it = buf + maxn * 10 - 1;  int _x;
#define in(x)  for(x = getchar() - '0'; (c = getchar()) >= '0'; x = (x << 3) + (x << 1) + c - '0');
#define write(x)  *--it = ' ';  do{  *--it = x % 10 + '0';  }  while(x /= 10);

int n, q, cache[maxn];
struct Gauss{
	int a[lg], skip;
	Gauss(){
		memset(a, 0, sizeof a);
		skip = 0;
	}
	void add(int x){
		for(int i = lg - 1; i >= skip; i--)
			if(x >> i & 1)
				if(a[i])
					x ^= a[i];
				else{
					a[i] = x;
					break;
				}
		while(skip < lg && a[skip])
			skip++;
	}
	int val(){
		int ans = 0;
		for(int i = lg - 1; i >= 0; i--)
			if(ans < (ans ^ a[i]))
				ans ^= a[i];
		return ans;
	}
}  seg[maxn * 2];
Gauss operator +=(Gauss &a, const Gauss &b){
	for(int i = 0; i < lg; i++)
		if(b.a[i])
			a.add(b.a[i]);
	return a;
}
int main(){
	//ios::sync_with_stdio(0), cin.tie(0);
	//cin >> n;
	//scanf("%d", &n);
	in(n);
	for(int i = 0; i < n; i++){
		int x;
		//cin >> x;
		//scanf("%d", &x);
		in(x);
		seg[n + i].add(x);
	}
	for(int i = n - 1; i > 0; i--){
		seg[i] += seg[i << 1];
		seg[i] += seg[i << 1 | 1];
	}
	//cin >> q;
	//scanf("%d", &q);
	in(q);
	for(int i = 0; i < q; i++){
		int l, r;
		//cin >> l >> r;
		//scanf("%d%d", &l, &r);
		in(l);
		in(r);
		l--;
		Gauss ans;
		for(l += n, r += n; l < r; l >>= 1, r >>= 1){
			if(l & 1)
				ans += seg[l++];
			if(r & 1)
				ans += seg[--r];
		}
		//cout << ans.val() << '\n';
		cache[i] = ans.val();
	}
	for(int i = q - 1; i >= 0; i--){
		write(cache[i]);
	}
	puts(it);
}


// In the name of God.
// You are all thing and We're nothing.
// Ya Ali!

#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 17, lg = 20;

char c, buf[maxn * 10], *it = buf + maxn * 10 - 1;  int _x;
#define in(x)  for(x = getchar() - '0'; (c = getchar()) >= '0'; x = (x << 3) + (x << 1) + c - '0');
#define write(x)  *--it = ' ';  do{  *--it = x % 10 + '0';  }  while(x /= 10);

int n, q, cache[maxn], l[maxn], a[maxn];
vector<int> assign[maxn];
struct Gauss{
	int a[lg], skip;
	Gauss(){
		memset(a, 0, sizeof a);
		skip = 0;
	}
	void add(int x, int hint = lg - 1){
		for(int i = hint; i >= skip; i--)
			if(x >> i & 1)
				if(a[i])
					x ^= a[i];
				else{
					a[i] = x;
					break;
				}
		while(skip < lg && a[skip])
			skip++;
	}
	int val(){
		int ans = 0;
		for(int i = lg - 1; i >= 0; i--)
			if(ans < (ans ^ a[i]))
				ans ^= a[i];
		return ans;
	}
}  seg[maxn * 2];
Gauss operator +=(Gauss &a, const Gauss &b){
	for(int i = 0; i < lg; i++)
		if(b.a[i])
			a.add(b.a[i], i);
	return a;
}
void add(int i){
	int l = 0, r = i + 1;
	for(l += n, r += n; l < r; l >>= 1, r >>= 1){
		if(l & 1)
			seg[l++].add(a[i]);
		if(r & 1)
			seg[--r].add(a[i]);
	}
}
int main(){
	//ios::sync_with_stdio(0), cin.tie(0);
	//cin >> n;
	scanf("%d", &n);
	//in(n);
	for(int i = 0; i < n; i++){
		int x;
		//cin >> x;
		scanf("%d", &x);
		//in(x);
		a[i] = x;
	}
	//cin >> q;
	scanf("%d", &q);
	//in(q);
	for(int i = 0; i < q; i++){
		//cin >> l >> r;
		int r;
		scanf("%d%d", &l[i], &r);
		//in(l[i]);
		//in(r);
		r--;
		assign[r].push_back(i);
		l[i]--;
	}
	for(int r = 0; r < n; r++){
		add(r);
		for(auto i : assign[r]){
			Gauss ans;
			for(int p = l[i] + n; p; p >>= 1)
				ans += seg[p];
			cache[i] = ans.val();
		}
	}
	for(int i = q - 1; i >= 0; i--){
		write(cache[i]);
	}
	puts(it);
}


// In the name of God.
// You are all thing and We're nothing.
// Ya Ali!

#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 17, lg = 20;
int n, q;
struct Gauss{
	int a[lg];
	Gauss(){
		memset(a, 0, sizeof a);
	}
	void add(int x){
		for(int i = lg - 1; i >= 0; i--)
			if(x >> i & 1)
				if(a[i])
					x ^= a[i];
				else{
					a[i] = x;
					break;
				}
	}
	int val(){
		int ans = 0;
		for(int i = lg - 1; i >= 0; i--)
			if(ans < (ans ^ a[i]))
				ans ^= a[i];
		return ans;
	}
}  seg[maxn * 2];
Gauss operator +=(Gauss &a, const Gauss &b){
	for(int i = 0; i < lg; i++)
		if(b.a[i])
			a.add(b.a[i]);
	return a;
}
int main(){
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		seg[n + i].add(x);
	}
	for(int i = n - 1; i > 0; i--){
		seg[i] += seg[i << 1];
		seg[i] += seg[i << 1 | 1];
	}
	cin >> q;
	while(q--){
		int l, r;
		cin >> l >> r;
		l--;
		Gauss ans;
		for(l += n, r += n; l < r; l >>= 1, r >>= 1){
			if(l & 1)
				ans += seg[l++];
			if(r & 1)
				ans += seg[--r];
		}
		cout << ans.val() << '\n';
	}
}


// In the name of God.
// You are all thing and We're nothing.
// Ya Ali!

#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 17, lg = 20;
int n, q;
struct Gauss{
	int a[lg];
	Gauss(){
		memset(a, 0, sizeof a);
	}
	void add(int x){
		for(int i = lg - 1; i >= 0; i--)
			if(x >> i & 1)
				if(a[i])
					x ^= a[i];
				else{
					a[i] = x;
					break;
				}
	}
	int val(){
		int ans = 0;
		for(int i = lg - 1; i >= 0; i--)
			if(ans < (ans ^ a[i]))
				ans ^= a[i];
		return ans;
	}
}  sp[lg][maxn];
Gauss operator +=(Gauss &a, const Gauss &b){
	for(int i = 0; i < lg; i++)
		if(b.a[i])
			a.add(b.a[i]);
	return a;
}
int main(){
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		sp[0][i].add(x);
	}
	for(int k = 1; k < lg; k++)
		for(int i = 0; i + (1 << k) <= n; i++){
			sp[k][i] += sp[k - 1][i];
			sp[k][i] += sp[k - 1][i + (1 << k - 1)];
		}
	cin >> q;
	while(q--){
		int l, r;
		cin >> l >> r;
		l--;
		Gauss ans;
		for(int i = lg - 1; i >= 0; i--)
			if(l + (1 << i) <= r)
				ans += sp[i][l], l += 1 << i;
		cout << ans.val() << '\n';
	}
}


// In the name of God.
// You are all thing and We're nothing.
// Ya Ali!

#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 17, lg = 20;
int n, q;
struct Gauss{
	int a[lg], skip;
	Gauss(){
		memset(a, 0, sizeof a);
		skip = 0;
	}
	void add(int x){
		for(int i = lg - 1; i >= skip; i--)
			if(x >> i & 1)
				if(a[i])
					x ^= a[i];
				else{
					a[i] = x;
					break;
				}
		while(skip < lg && a[skip])
			skip++;
	}
	int val(){
		int ans = 0;
		for(int i = lg - 1; i >= 0; i--)
			if(ans < (ans ^ a[i]))
				ans ^= a[i];
		return ans;
	}
}  seg[maxn * 2];
Gauss operator +=(Gauss &a, const Gauss &b){
	for(int i = 0; i < lg; i++)
		if(b.a[i])
			a.add(b.a[i]);
	return a;
}
int main(){
	//ios::sync_with_stdio(0), cin.tie(0);
	//cin >> n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int x;
		//cin >> x;
		scanf("%d", &x);
		seg[n + i].add(x);
	}
	for(int i = n - 1; i > 0; i--){
		seg[i] += seg[i << 1];
		seg[i] += seg[i << 1 | 1];
	}
	//cin >> q;
	scanf("%d", &q);
	while(q--){
		int l, r;
		//cin >> l >> r;
		scanf("%d%d", &l, &r);
		l--;
		Gauss ans;
		for(l += n, r += n; l < r; l >>= 1, r >>= 1){
			if(l & 1)
				ans += seg[l++];
			if(r & 1)
				ans += seg[--r];
		}
		//cout << ans.val() << '\n';
		printf("%d\n", ans.val());
	}
}


// In the name of God.
// You are all thing and We're nothing.
// Ya Ali!

#include <bits/stdc++.h>
using namespace std;

const int maxn = 5e5 + 17, lg = 20;
int n, q;
struct Gauss{
	int a[lg];
	Gauss(){
		memset(a, 0, sizeof a);
	}
	void add(int x){
		for(int i = lg - 1; i >= 0; i--)
			if(x >> i & 1)
				if(a[i])
					x ^= a[i];
				else{
					a[i] = x;
					break;
				}
	}
	int val(){
		int ans = 0;
		for(int i = lg - 1; i >= 0; i--)
			if(ans < (ans ^ a[i]))
				ans ^= a[i];
		return ans;
	}
}  seg[maxn * 2];
Gauss operator +=(Gauss &a, const Gauss &b){
	for(int i = 0; i < lg; i++)
		if(b.a[i])
			a.add(b.a[i]);
	return a;
}
int main(){
	//ios::sync_with_stdio(0), cin.tie(0);
	//cin >> n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int x;
		//cin >> x;
		scanf("%d", &x);
		seg[n + i].add(x);
	}
	for(int i = n - 1; i > 0; i--){
		seg[i] += seg[i << 1];
		seg[i] += seg[i << 1 | 1];
	}
	//cin >> q;
	scanf("%d", &q);
	while(q--){
		int l, r;
		//cin >> l >> r;
		scanf("%d%d", &l, &r);
		l--;
		Gauss ans;
		for(l += n, r += n; l < r; l >>= 1, r >>= 1){
			if(l & 1)
				ans += seg[l++];
			if(r & 1)
				ans += seg[--r];
		}
		//cout << ans.val() << '\n';
		printf("%d\n", ans.val());
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define N 500005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';
ll arr[N];

const int me = 20;

struct Gauss {
  int table[me];

  Gauss() {
    for (int i = 0; i < me; i++) {
      table[i] = 0;
    }
  }

  int size() {
    int ans = 0;
    for (int i = 0; i < me; i++) {
      if (table[i])
        ans++;
    }
    return ans;
  }

  bool can(int x) {
    for (int i = me - 1; i >= 0; i--) {
      x = std::min(x, x ^ table[i]);
    }
    return x == 0;
  }

  void add(int x) {
    for (int i = me - 1; i >= 0 && x; i--) {
      if (table[i] == 0) {
        table[i] = x;
        x = 0;
      } else {
        x = std::min(x, x ^ table[i]);
      }
    }
  }

  int best() {
    int x = 0;
    for (int i = me - 1; i >= 0; i--) {
      x = std::max(x, x ^ table[i]);
    }
    return x;
  }

  void merge(Gauss &A) {
    for (ll i = me - 1; i >= 0; i--)
      add(A.table[i]);
  }
};

vector<ll> tr[N * 4];
// Sample Problem 1: http://codeforces.com/contest/959/problem/F

// Sample Solution 1: http://codeforces.com/contest/959/submission/39772298
// My solution 1: https://codeforces.com/contest/959/submission/48297451

/*
 for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    if (i != 1)
      store[i] = store[i - 1];

    store[i].push(x);
    store[i].eliminate();
  }
  now lets say if wanna find number of subsequences upto L with xor x
  Gaussian curr = store[l];
    curr.push(x);
    curr.eliminate();
    // i have to see if x can be obtained as linear combination,so if basis
    // vector remains unchanged after addidtion of x,then we can obviously
    // obtain(i mean the previous set of vectors which spanned prev set(upto L)
    // also can span x

    if (store[l].redsize == curr.redsize) {
      cout << power(2, store[l].origsize - store[l].redsize, mod) << en;
    } else
      cout << 0 << en;
 */
// just do memset(tr,0,sizeof(tr))
ll arr2[N][2];
ll ans[N];

void update(ll l, ll r, ll index, ll ogL, ll ogR, ll si = 1) {

  if (ogL == ogR)
    return;
  ll mid = (ogL + ogR) >> 1;

  //[l:mid],[mid+1:r]

  if (l <= mid && r > mid && l >= ogL && r <= ogR) {
    tr[si].push_back(index);
    return;
  }

  if (r <= mid) {
    update(l, r, index, ogL, mid, si << 1);
  } else
    update(l, r, index, mid + 1, ogR, (si << 1) | 1);
}

void query(ll ogL, ll ogR, ll si = 1) {
  if (ogL == ogR)
    return;
  ll mid = (ogL + ogR) >> 1;

  if (tr[si].size() == 0) {
    query(ogL, mid, (si << 1));
    query(mid + 1, ogR, (si << 1) | 1);
    return;
  }

  Gauss storeLeft[mid - ogL + 1], storeRight[ogR - mid];
  Gauss running;
  for (ll i = mid; i >= ogL; i--) {
    running.add(arr[i]);
    storeLeft[mid - i] = running;
  }
  running = Gauss();
  for (ll i = mid + 1; i <= ogR; i++) {
    running.add(arr[i]);
    storeRight[i - mid - 1] = running;
  }

  for (ll x : tr[si]) {
    Gauss left = storeLeft[mid - arr2[x][0]];
    Gauss right = storeRight[arr2[x][1] - mid - 1];

    left.merge(right);
    ans[x] = left.best();
  }

  query(ogL, mid, (si << 1));
  query(mid + 1, ogR, (si << 1) | 1);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];
  ll q;
  cin >> q;
  for (ll i = 1; i <= q; i++) {
    cin >> arr2[i][0] >> arr2[i][1];
    if (arr2[i][0] == arr2[i][1]) {
      ans[i] = arr[arr2[i][0]];
      continue;
    }
    update(arr2[i][0], arr2[i][1], i, 1, n);
  }
  query(1, n);
  for (ll i = 1; i <= q; i++)
    cout << ans[i] << en;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define N 500005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';
ll arr[N];

//
// Created by cs160 on 12-01-2019.
//

// Logic:
// https://math.stackexchange.com/questions/48682/maximization-with-xor-operator

// dont use anything else execpt this(no typedef long long int ll)
//#define int long long;
// typedef int ll

struct Gaussian {
  int no_of_bits = 20;
  vector<int> v;
  int set, // set->maximise xor value
      origsize = 0,
      redsize =
          0; // original number of rows,number of non-zero rows(cnt of basis)

  void push(int val) { // insert new row
    origsize++;
    if (val)
      v.push_back(val);
  }

  void clear() {
    v.clear();
    set = 0, redsize = 0;
  }

  void eliminate() { // perform elimination
    set = redsize = 0;
    for (int bit = no_of_bits; bit >= 0; bit--) {
      bool check = false;
      for (int i = redsize; i < v.size(); i++) {
        if ((v[i] >> bit) & 1) {
          swap(v[i], v[redsize]);
          check = true;
          break;
        }
      }
      if (check) {

        for (int i = redsize + 1; i < v.size(); i++) {
          if ((v[i] >> bit) & 1)
            v[i] ^= v[redsize];
        }
        redsize++;
      }
    }
    for (ll x : v) {
      if ((set ^ x) > set)
        set ^= x;
    }
    v.resize(redsize);
  }

  Gaussian &operator=(Gaussian &orig) { // store[i]=store[i-1]
    v = orig.v;
    set = orig.set;
    redsize = orig.redsize;
    origsize = orig.origsize;
    return *this;
  }
};
vector<ll> tr[N * 4];
// Sample Problem 1: http://codeforces.com/contest/959/problem/F

// Sample Solution 1: http://codeforces.com/contest/959/submission/39772298
// My solution 1: https://codeforces.com/contest/959/submission/48297451

/*
 for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    if (i != 1)
      store[i] = store[i - 1];

    store[i].push(x);
    store[i].eliminate();
  }
  now lets say if wanna find number of subsequences upto L with xor x
  Gaussian curr = store[l];
    curr.push(x);
    curr.eliminate();
    // i have to see if x can be obtained as linear combination,so if basis
    // vector remains unchanged after addidtion of x,then we can obviously
    // obtain(i mean the previous set of vectors which spanned prev set(upto L)
    // also can span x

    if (store[l].redsize == curr.redsize) {
      cout << power(2, store[l].origsize - store[l].redsize, mod) << en;
    } else
      cout << 0 << en;
 */
// just do memset(tr,0,sizeof(tr))
ll arr2[N][2];
ll ans[N];
void update(ll l, ll r, ll index, ll ogL, ll ogR, ll si = 1) {

  if (ogL == ogR)
    return;
  ll mid = (ogL + ogR) >> 1;

  //[l:mid],[mid+1:r]

  if (l <= mid && r > mid) {
    tr[si].push_back(index);
    return;
  }

  if (r <= mid) {
    update(l, r, index, ogL, mid, si << 1);
  } else
    update(l, r, index, mid + 1, r, (si << 1) | 1);
}
vector<Gaussian> storeLeft, storeRight;
void query(ll ogL, ll ogR, ll si = 1) {
  if (ogL == ogR)
    return;
  ll mid = (ogL + ogR) >> 1;
  if (tr[si].size() == 0) {
    query(ogL, mid, (si << 1));
    query(mid + 1, ogR, (si << 1) | 1);
    return;
  }

  storeLeft.resize(mid - ogL + 1);
  storeRight.resize(ogR - mid);

  for (ll i = mid; i >= ogL; i--) {
    if (i != mid)
      storeLeft[mid - i] = storeLeft[mid - i - 1];
    else
      storeLeft[mid - i].clear();
    storeLeft[mid - i].push(arr[i]);
    storeLeft[mid - i].eliminate();
  }

  for (ll i = mid + 1; i <= ogR; i++) {
    if (i != mid + 1)
      storeRight[i - mid - 1] = storeRight[i - mid - 1 - 1];
    else
      storeRight[i - mid - 1].clear();
    storeRight[i - mid - 1].push(arr[i]);
    storeRight[i - mid - 1].eliminate();
  }

  for (ll x : tr[si]) {
    Gaussian left = storeLeft[mid - arr2[x][0]];
    Gaussian right = storeRight[arr2[x][1] - mid - 1];
    if (left.v.size() < right.v.size()) {
      for (ll x : left.v)
        right.push(x);
      right.eliminate();
      ans[x] = right.set;
    } else {
      for (ll x : right.v)
        left.push(x);
      left.eliminate();
      ans[x] = left.set;
    }
  }

  query(ogL, mid, (si << 1));
  query(mid + 1, ogR, (si << 1) | 1);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];
  ll q;
  cin >> q;
  for (ll i = 1; i <= q; i++) {
    cin >> arr2[i][0] >> arr2[i][1];
    if (arr2[i][0] == arr2[i][1]) {
      ans[i] = arr[arr2[i][0]];
      continue;
    }
    update(arr2[i][0], arr2[i][1], i, 1, n);
  }
  query(1, n);
  for (ll i = 1; i <= q; i++)
    cout << ans[i] << en;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define N 500005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';
ll arr[N];

//
// Created by cs160 on 12-01-2019.
//

// Logic:
// https://math.stackexchange.com/questions/48682/maximization-with-xor-operator

// dont use anything else execpt this(no typedef long long int ll)
//#define int long long;
// typedef int ll

struct Gaussian {
  int no_of_bits = 20;
  vector<int> v;
  int set, // set->maximise xor value
      origsize = 0,
      redsize =
          0; // original number of rows,number of non-zero rows(cnt of basis)

  void push(int val) { // insert new row
    origsize++;
    if (val)
      v.push_back(val);
  }

  void clear() {
    v.clear();
    set = 0, redsize = 0;
  }

  void eliminate() { // perform elimination
    set = redsize = 0;
    for (int bit = no_of_bits; bit >= 0; bit--) {
      bool check = false;
      for (int i = redsize; i < v.size(); i++) {
        if ((v[i] >> bit) & 1) {
          swap(v[i], v[redsize]);
          check = true;
          break;
        }
      }
      if (check) {

        for (int i = redsize + 1; i < v.size(); i++) {
          if ((v[i] >> bit) & 1)
            v[i] ^= v[redsize];
        }
        redsize++;
      }
    }
    for (ll x : v) {
      if ((set ^ x) > set)
        set ^= x;
    }
    v.resize(redsize);
  }

  Gaussian &operator=(Gaussian &orig) { // store[i]=store[i-1]
    v = orig.v;
    set = orig.set;
    redsize = orig.redsize;
    origsize = orig.origsize;
    return *this;
  }
};
Gaussian tr[N * 4];
// Sample Problem 1: http://codeforces.com/contest/959/problem/F

// Sample Solution 1: http://codeforces.com/contest/959/submission/39772298
// My solution 1: https://codeforces.com/contest/959/submission/48297451

/*
 for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    if (i != 1)
      store[i] = store[i - 1];

    store[i].push(x);
    store[i].eliminate();
  }
  now lets say if wanna find number of subsequences upto L with xor x
  Gaussian curr = store[l];
    curr.push(x);
    curr.eliminate();
    // i have to see if x can be obtained as linear combination,so if basis
    // vector remains unchanged after addidtion of x,then we can obviously
    // obtain(i mean the previous set of vectors which spanned prev set(upto L)
    // also can span x

    if (store[l].redsize == curr.redsize) {
      cout << power(2, store[l].origsize - store[l].redsize, mod) << en;
    } else
      cout << 0 << en;
 */
// just do memset(tr,0,sizeof(tr))

void update(ll val, ll ogL, ll ogR, ll si = 1) {

  if (ogL == ogR) {
    tr[si].push(arr[ogL]);
    tr[si].eliminate();
    return;
  }
  ll mid = (ogL + ogR) >> 1;
  update(val, ogL, mid, si << 1);
  update(val, mid + 1, ogR, (si << 1) | 1);

  if (tr[si << 1].redsize < tr[(si << 1) | 1].redsize) {
    tr[si] = tr[(si << 1) | 1];
    for (int x : tr[si << 1].v) {
      tr[si].push(x);
      tr[si].eliminate();
    }

  } else {
    tr[si] = tr[(si << 1)];
    for (int x : tr[(si << 1) | 1].v) {
      tr[si].push(x);
      tr[si].eliminate();
    }
  }
}

Gaussian query(ll l, ll r, ll ogL, ll ogR, ll si = 1) {

  Gaussian res;
  if ((r < ogL) or (l > ogR))
    return res;

  if ((ogL >= l) && (ogR <= r)) {
    return tr[si];
  }

  ll mid = (ogL + ogR) >> 1;
  Gaussian left = query(l, r, ogL, mid, (si << 1));
  Gaussian right = query(l, r, mid + 1, ogR, (si << 1) | 1);

  if (left.redsize < right.redsize) {
    for (int x : left.v) {
      right.push(x);
      right.eliminate();
    }

    return right;
  } else {
    for (int x : right.v) {
      left.push(x);
      left.eliminate();
    }

    return left;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];
  update(0, 1, n);
  ll q;
  cin >> q;
  while (q--) {
    ll l, r;
    cin >> l >> r;

    Gaussian res = query(l, r, 1, n);
    cout << res.set << en;
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define N 500005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';
ll arr[N];

//
// Created by cs160 on 12-01-2019.
//

// Logic:
// https://math.stackexchange.com/questions/48682/maximization-with-xor-operator

// dont use anything else execpt this(no typedef long long int ll)
//#define int long long;
// typedef int ll

struct Gaussian {
  int no_of_bits = 20;
  vector<int> v;
  int set, // set->maximise xor value
      origsize = 0,
      redsize =
          0; // original number of rows,number of non-zero rows(cnt of basis)

  void push(int val) { // insert new row
    origsize++;
    if (val)
      v.push_back(val);
  }

  void clear() {
    v.clear();
    set = 0, redsize = 0;
  }

  void eliminate() { // perform elimination
    set = redsize = 0;
    for (int bit = no_of_bits; bit >= 0; bit--) {
      bool check = false;
      for (int i = redsize; i < v.size(); i++) {
        if ((v[i] >> bit) & 1) {
          swap(v[i], v[redsize]);
          check = true;
          break;
        }
      }
      if (check) {

        for (int i = redsize + 1; i < v.size(); i++) {
          if ((v[i] >> bit) & 1)
            v[i] ^= v[redsize];
        }
        redsize++;
      }
    }
    for (ll x : v) {
      if ((set ^ x) > set)
        set ^= x;
    }
    v.resize(redsize);
  }

  Gaussian &operator=(Gaussian &orig) { // store[i]=store[i-1]
    v = orig.v;
    set = orig.set;
    redsize = orig.redsize;
    origsize = orig.origsize;
    return *this;
  }
};
vector<ll> tr[N * 4];
// Sample Problem 1: http://codeforces.com/contest/959/problem/F

// Sample Solution 1: http://codeforces.com/contest/959/submission/39772298
// My solution 1: https://codeforces.com/contest/959/submission/48297451

/*
 for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    if (i != 1)
      store[i] = store[i - 1];

    store[i].push(x);
    store[i].eliminate();
  }
  now lets say if wanna find number of subsequences upto L with xor x
  Gaussian curr = store[l];
    curr.push(x);
    curr.eliminate();
    // i have to see if x can be obtained as linear combination,so if basis
    // vector remains unchanged after addidtion of x,then we can obviously
    // obtain(i mean the previous set of vectors which spanned prev set(upto L)
    // also can span x

    if (store[l].redsize == curr.redsize) {
      cout << power(2, store[l].origsize - store[l].redsize, mod) << en;
    } else
      cout << 0 << en;
 */
// just do memset(tr,0,sizeof(tr))
ll arr2[N][2];
ll ans[N];
void update(ll l, ll r, ll index, ll ogL, ll ogR, ll si = 1) {

  if (ogL == ogR)
    return;
  ll mid = (ogL + ogR) >> 1;

  //[l:mid],[mid+1:r]

  if (l <= mid && r > mid && l >= ogL && r <= ogR) {
    tr[si].push_back(index);
    return;
  }

  if (r <= mid) {
    update(l, r, index, ogL, mid, si << 1);
  } else
    update(l, r, index, mid + 1, ogR, (si << 1) | 1);
}

void query(ll ogL, ll ogR, ll si = 1) {
  if (ogL == ogR)
    return;
  ll mid = (ogL + ogR) >> 1;

  if (tr[si].size() == 0) {
    query(ogL, mid, (si << 1));
    query(mid + 1, ogR, (si << 1) | 1);
    return;
  }

  Gaussian storeLeft[mid - ogL + 1], storeRight[ogR - mid];

  for (ll i = mid; i >= ogL; i--) {
    if (i != mid)
      storeLeft[mid - i] = storeLeft[mid - i - 1];
    assert((mid - i) >= 0 && (mid - i) < (mid - ogL + 1));
    storeLeft[mid - i].push(arr[i]);
    storeLeft[mid - i].eliminate();
  }

  for (ll i = mid + 1; i <= ogR; i++) {
    if (i != mid + 1)
      storeRight[i - mid - 1] = storeRight[i - mid - 1 - 1];
    assert((i - mid - 1) >= 0 && (i - mid - 1) < (ogR - mid));
    storeRight[i - mid - 1].push(arr[i]);
    storeRight[i - mid - 1].eliminate();
  }

  for (ll x : tr[si]) {
    Gaussian left = storeLeft[mid - arr2[x][0]];
    Gaussian right = storeRight[arr2[x][1] - mid - 1];
    if (left.v.size() < right.v.size()) {
      for (ll x : left.v)
        right.push(x);
      right.eliminate();
      ans[x] = right.set;
    } else {
      for (ll x : right.v)
        left.push(x);
      left.eliminate();
      ans[x] = left.set;
    }
  }

  query(ogL, mid, (si << 1));
  query(mid + 1, ogR, (si << 1) | 1);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];
  ll q;
  cin >> q;
  for (ll i = 1; i <= q; i++) {
    cin >> arr2[i][0] >> arr2[i][1];
    if (arr2[i][0] == arr2[i][1]) {
      ans[i] = arr[arr2[i][0]];
      continue;
    }
    update(arr2[i][0], arr2[i][1], i, 1, n);
  }
  query(1, n);
  for (ll i = 1; i <= q; i++)
    cout << ans[i] << en;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define N 500005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';
ll arr[N];

//
// Created by cs160 on 12-01-2019.
//

// Logic:
// https://math.stackexchange.com/questions/48682/maximization-with-xor-operator

// dont use anything else execpt this(no typedef long long int ll)
//#define int long long;
// typedef int ll

struct Gaussian {
  int no_of_bits = 20;
  vector<int> v;
  int set, // set->maximise xor value
      origsize = 0,
      redsize =
          0; // original number of rows,number of non-zero rows(cnt of basis)

  void push(int val) { // insert new row
    origsize++;
    if (val)
      v.push_back(val);
  }

  void clear() {
    v.clear();
    set = 0, redsize = 0;
  }

  void eliminate() { // perform elimination
    set = redsize = 0;
    for (int bit = no_of_bits; bit >= 0; bit--) {
      bool check = false;
      for (int i = redsize; i < v.size(); i++) {
        if ((v[i] >> bit) & 1) {
          swap(v[i], v[redsize]);
          check = true;
          break;
        }
      }
      if (check) {

        for (int i = redsize + 1; i < v.size(); i++) {
          if ((v[i] >> bit) & 1)
            v[i] ^= v[redsize];
        }
        redsize++;
      }
    }
    for (ll x : v) {
      if ((set ^ x) > set)
        set ^= x;
    }
    v.resize(redsize);
  }

  Gaussian &operator=(Gaussian &orig) { // store[i]=store[i-1]
    v = orig.v;
    set = orig.set;
    redsize = orig.redsize;
    origsize = orig.origsize;
    return *this;
  }
};
Gaussian tr[N * 4];
// Sample Problem 1: http://codeforces.com/contest/959/problem/F

// Sample Solution 1: http://codeforces.com/contest/959/submission/39772298
// My solution 1: https://codeforces.com/contest/959/submission/48297451

/*
 for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    if (i != 1)
      store[i] = store[i - 1];

    store[i].push(x);
    store[i].eliminate();
  }
  now lets say if wanna find number of subsequences upto L with xor x
  Gaussian curr = store[l];
    curr.push(x);
    curr.eliminate();
    // i have to see if x can be obtained as linear combination,so if basis
    // vector remains unchanged after addidtion of x,then we can obviously
    // obtain(i mean the previous set of vectors which spanned prev set(upto L)
    // also can span x

    if (store[l].redsize == curr.redsize) {
      cout << power(2, store[l].origsize - store[l].redsize, mod) << en;
    } else
      cout << 0 << en;
 */
// just do memset(tr,0,sizeof(tr))

void update(ll val, ll ogL, ll ogR, ll si = 1) {

  if (ogL == ogR) {

    tr[si].push(arr[ogL]);
    if (tr[si].v.size() > 30)
      tr[si].eliminate();
    return;
  }
  ll mid = (ogL + ogR) >> 1;
  update(val, ogL, mid, si << 1);
  update(val, mid + 1, ogR, (si << 1) | 1);

  if (tr[si << 1].redsize < tr[(si << 1) | 1].redsize) {
    tr[si] = tr[(si << 1) | 1];
    for (int x : tr[si << 1].v) {
      tr[si].push(x);
    }
    if (tr[si].v.size() > 30)
      tr[si].eliminate();

  } else {
    tr[si] = tr[(si << 1)];
    for (int x : tr[(si << 1) | 1].v) {
      tr[si].push(x);
    }
    if (tr[si].v.size() > 30)
      tr[si].eliminate();
  }
}

Gaussian query(ll l, ll r, ll ogL, ll ogR, ll si = 1) {

  Gaussian res;
  if ((r < ogL) or (l > ogR))
    return res;

  if ((ogL >= l) && (ogR <= r)) {
    return tr[si];
  }

  ll mid = (ogL + ogR) >> 1;
  Gaussian left = query(l, r, ogL, mid, (si << 1));
  Gaussian right = query(l, r, mid + 1, ogR, (si << 1) | 1);

  if (left.redsize < right.redsize) {
    for (int x : left.v) {
      right.push(x);
    }
    if (right.v.size() > 30)
      right.eliminate();

    return right;
  } else {
    for (int x : right.v) {
      left.push(x);
    }
    if (left.v.size() > 30)
      left.eliminate();

    return left;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];
  update(0, 1, n);
  ll q;
  cin >> q;
  while (q--) {
    ll l, r;
    cin >> l >> r;

    Gaussian res = query(l, r, 1, n);
    res.eliminate();
    cout << res.set << en;
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define N 500005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';
ll arr[N];

//
// Created by cs160 on 12-01-2019.
//

// Logic:
// https://math.stackexchange.com/questions/48682/maximization-with-xor-operator

// dont use anything else execpt this(no typedef long long int ll)
//#define int long long;
// typedef int ll

struct Gaussian {
  int no_of_bits = 20;
  vector<int> v;
  int set, // set->maximise xor value
      origsize = 0,
      redsize =
          0; // original number of rows,number of non-zero rows(cnt of basis)

  void push(int val) { // insert new row
    origsize++;
    if (val)
      v.push_back(val);
  }

  void clear() {
    v.clear();
    set = 0, redsize = 0;
  }

  void eliminate() { // perform elimination
    set = redsize = 0;
    for (int bit = no_of_bits; bit >= 0; bit--) {
      bool check = false;
      for (int i = redsize; i < v.size(); i++) {
        if ((v[i] >> bit) & 1) {
          swap(v[i], v[redsize]);
          check = true;
          break;
        }
      }
      if (check) {

        for (int i = redsize + 1; i < v.size(); i++) {
          if ((v[i] >> bit) & 1)
            v[i] ^= v[redsize];
        }
        redsize++;
      }
    }
    for (ll x : v) {
      if ((set ^ x) > set)
        set ^= x;
    }
    v.resize(redsize);
  }

  Gaussian &operator=(Gaussian &orig) { // store[i]=store[i-1]
    v = orig.v;
    set = orig.set;
    redsize = orig.redsize;
    origsize = orig.origsize;
    return *this;
  }
};
vector<ll> tr[N * 4];
// Sample Problem 1: http://codeforces.com/contest/959/problem/F

// Sample Solution 1: http://codeforces.com/contest/959/submission/39772298
// My solution 1: https://codeforces.com/contest/959/submission/48297451

/*
 for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    if (i != 1)
      store[i] = store[i - 1];

    store[i].push(x);
    store[i].eliminate();
  }
  now lets say if wanna find number of subsequences upto L with xor x
  Gaussian curr = store[l];
    curr.push(x);
    curr.eliminate();
    // i have to see if x can be obtained as linear combination,so if basis
    // vector remains unchanged after addidtion of x,then we can obviously
    // obtain(i mean the previous set of vectors which spanned prev set(upto L)
    // also can span x

    if (store[l].redsize == curr.redsize) {
      cout << power(2, store[l].origsize - store[l].redsize, mod) << en;
    } else
      cout << 0 << en;
 */
// just do memset(tr,0,sizeof(tr))
ll arr2[N][2];
ll ans[N];
void update(ll l, ll r, ll index, ll ogL, ll ogR, ll si = 1) {

  if (ogL == ogR)
    return;
  ll mid = (ogL + ogR) >> 1;

  //[l:mid],[mid+1:r]

  if (l <= mid && r > mid) {
    tr[si].push_back(index);
    return;
  }

  if (r <= mid) {
    update(l, r, index, ogL, mid, si << 1);
  } else
    update(l, r, index, mid + 1, r, (si << 1) | 1);
}
vector<Gaussian> storeLeft, storeRight;
void query(ll ogL, ll ogR, ll si = 1) {
  if (ogL == ogR)
    return;
  ll mid = (ogL + ogR) >> 1;
  if (tr[si].size() == 0) {
    query(ogL, mid, (si << 1));
    query(mid + 1, ogR, (si << 1) | 1);
    return;
  }

  storeLeft.resize(mid - ogL + 1);
  storeRight.resize(ogR - mid);

  for (ll i = mid; i >= ogL; i--) {
    if (i != mid)
      storeLeft[mid - i] = storeLeft[mid - i - 1];

    storeLeft[mid - i].push(arr[i]);
    storeLeft[mid - i].eliminate();
  }

  for (ll i = mid + 1; i <= ogR; i++) {
    if (i != mid + 1)
      storeRight[i - mid - 1] = storeRight[i - mid - 1 - 1];
    storeRight[i - mid - 1].push(arr[i]);
    storeRight[i - mid - 1].eliminate();
  }

  for (ll x : tr[si]) {
    Gaussian left = storeLeft[mid - arr2[x][0]];
    Gaussian right = storeRight[arr2[x][1] - mid - 1];
    if (left.v.size() < right.v.size()) {
      for (ll x : left.v)
        right.push(x);
      right.eliminate();
      ans[x] = right.set;
    } else {
      for (ll x : right.v)
        left.push(x);
      left.eliminate();
      ans[x] = left.set;
    }
  }

  query(ogL, mid, (si << 1));
  query(mid + 1, ogR, (si << 1) | 1);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];
  ll q;
  cin >> q;
  for (ll i = 1; i <= q; i++) {
    cin >> arr2[i][0] >> arr2[i][1];
    if (arr2[i][0] == arr2[i][1]) {
      ans[i] = arr[arr2[i][0]];
      continue;
    }
    update(arr2[i][0], arr2[i][1], i, 1, n);
  }
  query(1, n);
  for (ll i = 1; i <= q; i++)
    cout << ans[i] << en;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define N 500005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';
ll arr[N];

//
// Created by cs160 on 12-01-2019.
//

// Logic:
// https://math.stackexchange.com/questions/48682/maximization-with-xor-operator

// dont use anything else execpt this(no typedef long long int ll)
//#define int long long;
// typedef int ll

struct Gaussian {
  int no_of_bits = 20;
  vector<int> v;
  int set, // set->maximise xor value
      origsize = 0,
      redsize =
          0; // original number of rows,number of non-zero rows(cnt of basis)

  void push(int val) { // insert new row
    origsize++;
    if (val)
      v.push_back(val);
  }

  void clear() {
    v.clear();
    set = 0, redsize = 0;
  }

  void eliminate() { // perform elimination
    set = redsize = 0;
    for (int bit = no_of_bits; bit >= 0; bit--) {
      bool check = false;
      for (int i = redsize; i < v.size(); i++) {
        if ((v[i] >> bit) & 1) {
          swap(v[i], v[redsize]);
          check = true;
          break;
        }
      }
      if (check) {

        for (int i = redsize + 1; i < v.size(); i++) {
          if ((v[i] >> bit) & 1)
            v[i] ^= v[redsize];
        }
        redsize++;
      }
    }
    for (ll x : v) {
      if ((set ^ x) > set)
        set ^= x;
    }
    v.resize(redsize);
  }

  Gaussian &operator=(Gaussian &orig) { // store[i]=store[i-1]
    v = orig.v;
    set = orig.set;
    redsize = orig.redsize;
    origsize = orig.origsize;
    return *this;
  }
};
vector<ll> tr[N * 4];
// Sample Problem 1: http://codeforces.com/contest/959/problem/F

// Sample Solution 1: http://codeforces.com/contest/959/submission/39772298
// My solution 1: https://codeforces.com/contest/959/submission/48297451

/*
 for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    if (i != 1)
      store[i] = store[i - 1];

    store[i].push(x);
    store[i].eliminate();
  }
  now lets say if wanna find number of subsequences upto L with xor x
  Gaussian curr = store[l];
    curr.push(x);
    curr.eliminate();
    // i have to see if x can be obtained as linear combination,so if basis
    // vector remains unchanged after addidtion of x,then we can obviously
    // obtain(i mean the previous set of vectors which spanned prev set(upto L)
    // also can span x

    if (store[l].redsize == curr.redsize) {
      cout << power(2, store[l].origsize - store[l].redsize, mod) << en;
    } else
      cout << 0 << en;
 */
// just do memset(tr,0,sizeof(tr))
ll arr2[N][2];
ll ans[N];
void update(ll l, ll r, ll index, ll ogL, ll ogR, ll si = 1) {

  if (ogL == ogR)
    return;
  ll mid = (ogL + ogR) >> 1;

  //[l:mid],[mid+1:r]

  if (l <= mid && r > mid) {
    tr[si].push_back(index);
    return;
  }

  if (r <= mid) {
    update(l, r, index, ogL, mid, si << 1);
  } else
    update(l, r, index, mid + 1, r, (si << 1) | 1);
}

void query(ll ogL, ll ogR, ll si = 1) {
  if (ogL == ogR)
    return;
  ll mid = (ogL + ogR) >> 1;
  if (tr[si].size() == 0) {
    query(ogL, mid, (si << 1));
    query(mid + 1, ogR, (si << 1) | 1);
    return;
  }

  Gaussian storeLeft[mid - ogL + 1], storeRight[ogR - mid];

  for (ll i = mid; i >= ogL; i--) {
    if (i != mid)
      storeLeft[mid - i] = storeLeft[mid - i - 1];

    storeLeft[mid - i].push(arr[i]);
    storeLeft[mid - i].eliminate();
  }

  for (ll i = mid + 1; i <= ogR; i++) {
    if (i != mid + 1)
      storeRight[i - mid - 1] = storeRight[i - mid - 1 - 1];
    storeRight[i - mid - 1].push(arr[i]);
    storeRight[i - mid - 1].eliminate();
  }

  for (ll x : tr[si]) {
    Gaussian left = storeLeft[mid - arr2[x][0]];
    Gaussian right = storeRight[arr2[x][1] - mid - 1];
    if (left.v.size() < right.v.size()) {
      for (ll x : left.v)
        right.push(x);
      right.eliminate();
      ans[x] = right.set;
    } else {
      for (ll x : right.v)
        left.push(x);
      left.eliminate();
      ans[x] = left.set;
    }
  }

  query(ogL, mid, (si << 1));
  query(mid + 1, ogR, (si << 1) | 1);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];
  ll q;
  cin >> q;
  for (ll i = 1; i <= q; i++) {
    cin >> arr2[i][0] >> arr2[i][1];
    if (arr2[i][0] == arr2[i][1]) {
      ans[i] = arr[arr2[i][0]];
      continue;
    }
    update(arr2[i][0], arr2[i][1], i, 1, n);
  }
  query(1, n);
  for (ll i = 1; i <= q; i++)
    cout << ans[i] << en;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define N 500005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';
ll arr[N];

//
// Created by cs160 on 12-01-2019.
//

// Logic:
// https://math.stackexchange.com/questions/48682/maximization-with-xor-operator

// dont use anything else execpt this(no typedef long long int ll)
//#define int long long;
// typedef int ll

struct Gaussian {
  int no_of_bits = 20;
  vector<int> v;
  int set, // set->maximise xor value
      origsize = 0,
      redsize =
          0; // original number of rows,number of non-zero rows(cnt of basis)

  void push(int val) { // insert new row
    origsize++;
    if (val)
      v.push_back(val);
  }

  void clear() {
    v.clear();
    set = 0, redsize = 0;
  }

  void eliminate() { // perform elimination
    set = redsize = 0;
    for (int bit = no_of_bits; bit >= 0; bit--) {
      bool check = false;
      for (int i = redsize; i < v.size(); i++) {
        if ((v[i] >> bit) & 1) {
          swap(v[i], v[redsize]);
          check = true;
          break;
        }
      }
      if (check) {

        for (int i = redsize + 1; i < v.size(); i++) {
          if ((v[i] >> bit) & 1)
            v[i] ^= v[redsize];
        }
        redsize++;
      }
    }
    for (ll x : v) {
      if ((set ^ x) > set)
        set ^= x;
    }
    v.resize(redsize);
  }

  Gaussian &operator=(Gaussian &orig) { // store[i]=store[i-1]
    v = orig.v;
    set = orig.set;
    redsize = orig.redsize;
    origsize = orig.origsize;
    return *this;
  }
};
Gaussian tr[N * 4];
// Sample Problem 1: http://codeforces.com/contest/959/problem/F

// Sample Solution 1: http://codeforces.com/contest/959/submission/39772298
// My solution 1: https://codeforces.com/contest/959/submission/48297451

/*
 for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    if (i != 1)
      store[i] = store[i - 1];

    store[i].push(x);
    store[i].eliminate();
  }
  now lets say if wanna find number of subsequences upto L with xor x
  Gaussian curr = store[l];
    curr.push(x);
    curr.eliminate();
    // i have to see if x can be obtained as linear combination,so if basis
    // vector remains unchanged after addidtion of x,then we can obviously
    // obtain(i mean the previous set of vectors which spanned prev set(upto L)
    // also can span x

    if (store[l].redsize == curr.redsize) {
      cout << power(2, store[l].origsize - store[l].redsize, mod) << en;
    } else
      cout << 0 << en;
 */
// just do memset(tr,0,sizeof(tr))

void update(ll val, ll ogL, ll ogR, ll si = 1) {

  if (ogL == ogR) {
    tr[si].push(arr[ogL]);
    tr[si].eliminate();
    return;
  }
  ll mid = (ogL + ogR) >> 1;
  update(val, ogL, mid, si << 1);
  update(val, mid + 1, ogR, (si << 1) | 1);

  if (tr[si << 1].redsize < tr[(si << 1) | 1].redsize) {
    tr[si] = tr[(si << 1) | 1];
    for (int x : tr[si << 1].v) {
      tr[si].push(x);
    }
    tr[si].eliminate();

  } else {
    tr[si] = tr[(si << 1)];
    for (int x : tr[(si << 1) | 1].v) {
      tr[si].push(x);
    }
    tr[si].eliminate();
  }
}

Gaussian query(ll l, ll r, ll ogL, ll ogR, ll si = 1) {

  Gaussian res;
  if ((r < ogL) or (l > ogR))
    return res;

  if ((ogL >= l) && (ogR <= r)) {
    return tr[si];
  }

  ll mid = (ogL + ogR) >> 1;
  Gaussian left = query(l, r, ogL, mid, (si << 1));
  Gaussian right = query(l, r, mid + 1, ogR, (si << 1) | 1);

  if (left.redsize < right.redsize) {
    for (int x : left.v) {
      right.push(x);
    }
    right.eliminate();

    return right;
  } else {
    for (int x : right.v) {
      left.push(x);
    }
    left.eliminate();

    return left;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];
  update(0, 1, n);
  ll q;
  cin >> q;
  while (q--) {
    ll l, r;
    cin >> l >> r;

    Gaussian res = query(l, r, 1, n);
    cout << res.set << en;
  }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define N 500005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';
ll arr[N];

//
// Created by cs160 on 12-01-2019.
//

// Logic:
// https://math.stackexchange.com/questions/48682/maximization-with-xor-operator

// dont use anything else execpt this(no typedef long long int ll)
//#define int long long;
// typedef int ll

struct Gaussian {
  int no_of_bits = 20;
  vector<int> v;
  int set, // set->maximise xor value
      origsize = 0,
      redsize =
          0; // original number of rows,number of non-zero rows(cnt of basis)

  void push(int val) { // insert new row
    origsize++;
    if (val)
      v.push_back(val);
  }

  void clear() {
    v.clear();
    set = 0, redsize = 0;
  }

  void eliminate() { // perform elimination
    set = redsize = 0;
    for (int bit = no_of_bits; bit >= 0; bit--) {
      bool check = false;
      for (int i = redsize; i < v.size(); i++) {
        if ((v[i] >> bit) & 1) {
          swap(v[i], v[redsize]);
          check = true;
          break;
        }
      }
      if (check) {

        for (int i = redsize + 1; i < v.size(); i++) {
          if ((v[i] >> bit) & 1)
            v[i] ^= v[redsize];
        }
        redsize++;
      }
    }
    for (ll x : v) {
      if ((set ^ x) > set)
        set ^= x;
    }
    v.resize(redsize);
  }

  Gaussian &operator=(Gaussian &orig) { // store[i]=store[i-1]
    v = orig.v;
    set = orig.set;
    redsize = orig.redsize;
    origsize = orig.origsize;
    return *this;
  }
};
Gaussian tr[N * 4];
// Sample Problem 1: http://codeforces.com/contest/959/problem/F

// Sample Solution 1: http://codeforces.com/contest/959/submission/39772298
// My solution 1: https://codeforces.com/contest/959/submission/48297451

/*
 for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;
    if (i != 1)
      store[i] = store[i - 1];

    store[i].push(x);
    store[i].eliminate();
  }
  now lets say if wanna find number of subsequences upto L with xor x
  Gaussian curr = store[l];
    curr.push(x);
    curr.eliminate();
    // i have to see if x can be obtained as linear combination,so if basis
    // vector remains unchanged after addidtion of x,then we can obviously
    // obtain(i mean the previous set of vectors which spanned prev set(upto L)
    // also can span x

    if (store[l].redsize == curr.redsize) {
      cout << power(2, store[l].origsize - store[l].redsize, mod) << en;
    } else
      cout << 0 << en;
 */
// just do memset(tr,0,sizeof(tr))

void update(ll val, ll ogL, ll ogR, ll si = 1) {

  if (ogL == ogR) {

    tr[si].push(arr[ogL]);
    if (tr[si].v.size() > 20)
      tr[si].eliminate();
    return;
  }
  ll mid = (ogL + ogR) >> 1;
  update(val, ogL, mid, si << 1);
  update(val, mid + 1, ogR, (si << 1) | 1);

  if (tr[si << 1].redsize < tr[(si << 1) | 1].redsize) {
    tr[si] = tr[(si << 1) | 1];
    for (int x : tr[si << 1].v) {
      tr[si].push(x);
    }
    if (tr[si].v.size() > 20)
      tr[si].eliminate();

  } else {
    tr[si] = tr[(si << 1)];
    for (int x : tr[(si << 1) | 1].v) {
      tr[si].push(x);
    }
    if (tr[si].v.size() > 20)
      tr[si].eliminate();
  }
}

Gaussian query(ll l, ll r, ll ogL, ll ogR, ll si = 1) {

  Gaussian res;
  if ((r < ogL) or (l > ogR))
    return res;

  if ((ogL >= l) && (ogR <= r)) {
    return tr[si];
  }

  ll mid = (ogL + ogR) >> 1;
  Gaussian left = query(l, r, ogL, mid, (si << 1));
  Gaussian right = query(l, r, mid + 1, ogR, (si << 1) | 1);

  if (left.redsize < right.redsize) {
    for (int x : left.v) {
      right.push(x);
    }
    if (right.v.size() > 20)
      right.eliminate();

    return right;
  } else {
    for (int x : right.v) {
      left.push(x);
    }
    if (left.v.size() > 20)
      left.eliminate();

    return left;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin >> n;
  for (ll i = 1; i <= n; i++)
    cin >> arr[i];
  update(0, 1, n);
  ll q;
  cin >> q;
  while (q--) {
    ll l, r;
    cin >> l >> r;

    Gaussian res = query(l, r, 1, n);
    res.eliminate();
    cout << res.set << en;
  }

  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int len=5e5+10;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
struct Node{
	int l,r,id;
	bool operator<(const Node a)const
	{
		return r<a.r;
	}
}Q[len];
int a[len],ans[len],p[30],pos[30];
void add(int x,int id)
{
	for(int i=20;i>=0;--i)
	{
		if(x&(1<<i))
		{
			if(!p[i])
			{
				p[i]=x;
				pos[i]=id;
				return ;
			}

			if(id>pos[i])swap(id,pos[i]),swap(x,p[i]);
			x^=p[i];
		}
	}
}
int query(int l)
{
	int ans=0;
	for(int i=20;i>=0;--i)
		if(pos[i]>=l&&(ans^p[i])>ans)ans^=p[i];
	return ans;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	int q;
	cin>>q;
	for(int i=1;i<=q;++i)
	{
		scanf("%d%d",&Q[i].l,&Q[i].r);
		Q[i].id=i;
	}
	sort(Q+1,Q+1+q);
	int l=1;
	for(int i=1;i<=q;++i)
	{
		while(l<=n&&l<=Q[i].r)add(a[l],l),l++;
		ans[Q[i].id]=query(Q[i].l);
	}
	for(int i=1;i<=q;++i)printf("%d\n",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int len=5e5+10;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
struct Node{
	int l,r,id;
	bool operator<(const Node a)const
	{
		return r<a.r;
	}
}Q[len];
int a[len],ans[len],p[30],pos[30];
void add(int x,int id)
{
	for(int i=20;i>=0;--i)
	{
		if(x&(1<<i))
		{
			if(!p[i])
			{
				p[i]=x;
				pos[i]=id;
				return ;
			}

			if(id>pos[i])swap(id,pos[i]),swap(x,p[i]);
			x^=p[i];
		}
	}
}
int query(int l)
{
	int ans=0;
	for(int i=20;i>=0;--i)
		if(pos[i]>=l&&(ans^p[i])>ans)ans^=p[i];
	return ans;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	int q;
	cin>>q;
	for(int i=1;i<=q;++i)
	{
		scanf("%d%d",&Q[i].l,&Q[i].r);
		Q[i].id=i;
	}
	sort(Q+1,Q+1+q);
	int l=1;
	for(int i=1;i<=q;++i)
	{
		while(l<=n&&l<=Q[i].r)add(a[l],l),l++;
		ans[Q[i].id]=query(Q[i].l);
	}
	for(int i=1;i<=q;++i)printf("%d\n",ans);
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int len=5e5+10;
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
struct Node{
	int l,r,id;
	bool operator<(Node a)const
	{
		return r<a.r;
	}
}Q[len];
int a[len],ans[len],p[30],pos[30];
void add(int x,int id)
{
	for(int i=20;i>=0;--i)
	{
		if(x&(1<<i))
		{
			if(!p[i])
			{
				p[i]=x;
				pos[i]=id;
				return ;
			}

			if(id>pos[i])swap(id,pos[i]),swap(x,p[i]);
			x^=p[i];
		}
	}
}
int query(int l)
{
	int ans=0;
	for(int i=20;i>=0;--i)
		if(pos[i]>=l&&(ans^p[i])>ans)ans^=p[i];
	return ans;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)cin>>a[i];
	int q;
	cin>>q;
	for(int i=1;i<=q;++i)
	{
		cin>>Q[i].l>>Q[i].r;
		Q[i].id=i;
	}
	sort(Q+1,Q+1+q);
	int l=1;
	for(int i=1;i<=q;++i)
	{
		while(l<=n&&l<=Q[i].r)add(a[l],l),l++;
		ans[Q[i].id]=query(Q[i].l);
	}
	for(int i=1;i<=q;++i)cout<<ans[i]<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define mem(a) memset(a,0,sizeof(a))
#define sqr(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int mn = 5e5 + 5;

int n, m;
int a[mn], p[25], pos[25];

void ins(int i) {
    int id=i,x=a[i];
    for (int j = 21; j >= 0; j--) {
        if (!(x >> j)) continue;  //对线性基的这一位没有贡献
        if (!p[j]) {
            p[j] = x;
            pos[j] = id;
            break;
        }  //选入线性基中
        swap(x,p[j]);
        swap(id,pos[j]);
        x^=p[j];
    };
    //for(int j=0;j<3;j++) printf("%d!%d %d %d\n",i,j,p[j],pos[j]);
}

int query(int l){
    int ans=0;
    for (int j = 21; j >= 0; j--) {
        if (p[j]&&pos[j]>=l&&(ans^p[j])>ans) ans^=p[j];
        //printf("!%d %d %d %d\n",j,ans,pos[j],l);
    }
    return ans;
}

struct query {
    int l, r, id;
    bool operator<(const query &p) const {
        return r < p.r;
    }
} q[mn];

int ans[mn];

int main() {
#ifdef trote
    freopen("../1.txt", "r", stdin);
#endif
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) scanf("%d%d", &q[i].l, &q[i].r), q[i].id = i;
    sort(q + 1, q + m + 1);
    int r=1;
    for (int i=1;i<=m;i++) {
        while(r<=q[i].r) ins(r++);
        ans[q[i].id]=query(q[i].l);
        //printf("%d %d %d %d %d\n",i,r,q[i].l,q[i].r,q[i].id);
        //for(int j=0;j<3;j++) printf("%d %d %d\n",j,p[j],pos[j]);
    }
    for(int i=1;i<=m;i++) printf("%d\n",ans[i]);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define mem(a) memset(a,0,sizeof(a))
#define sqr(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int mn = 5e5 + 5;

int n, m;
int a[mn], p[25], pos[25];

void ins(int i) {
	for (int j = 21; j >= 0; j--) {
		if (!(a[i] >> j)) continue;  //对线性基的这一位没有贡献
		if (!p[j]) {
			p[j] = a[i];
			pos[j] = i;
			break;
		}  //选入线性基中
		if (pos[j]<i) pos[j]=i,p[j]=a[i];
		a[i] ^= p[j];
	}
}

int query(int l){
	int ans=0;
	for (int j = 21; j >= 0; j--) {
		if (p[j]&&pos[j]>=l&&(ans^p[j])>ans) ans^=p[j];
		//printf("!%d %d %d %d\n",j,ans,pos[j],l);
	}
	return ans;
}

struct query {
	int l, r, id;
	bool operator<(const query &p) const {
		return r < p.r;
	}
} q[mn];

int ans[mn];

int main() {
#ifdef LOCAL
	freopen("../1.txt", "r", stdin);
#endif
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	scanf("%d", &m);
	for (int i = 1; i <= m; i++) scanf("%d%d", &q[i].l, &q[i].r), q[i].id = i;
	sort(q + 1, q + m + 1);
	int r=1;
	for (int i=1;i<=m;i++) {
		while(r<=q[i].r) ins(r++);
		ans[q[i].id]=query(q[i].l);
		printf("%d %d %d %d %d\n",i,r,q[i].l,q[i].r,q[i].id);
		for(int j=0;j<3;j++) printf("%d %d %d\n",j,p[j],pos[j]);
	}
	for(int i=1;i<=m;i++) printf("%d\n",ans[i]);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define mem(a) memset(a,0,sizeof(a))
#define sqr(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int mn = 5e5 + 5;

int n, m;
int a[mn], p[25], pos[25];

void ins(int i) {
    int id=i,x=a[i];
    for (int j = 21; j >= 0; j--) {
        if (!(x >> j)) continue;  //对线性基的这一位没有贡献
        if (!p[j]) {
            p[j] = x;
            pos[j] = id;
            break;
        }  //选入线性基中
        if (id>pos[j]){
            swap(x,p[j]);
            swap(id,pos[j]);
        }
        x^=p[j];
    };
    //for(int j=0;j<3;j++) printf("%d!%d %d %d\n",i,j,p[j],pos[j]);
}

int query(int l){
    int ans=0;
    for (int j = 21; j >= 0; j--) {
        if (pos[j]>=l&&(ans^p[j])>ans) ans^=p[j];
        //printf("!%d %d %d %d\n",j,ans,pos[j],l);
    }
    return ans;
}

struct query {
    int l, r, id;
    bool operator<(const query &p) const {
        return r < p.r;
    }
} q[mn];

int ans[mn];

int main() {
#ifdef trote
    freopen("../1.txt", "r", stdin);
#endif
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) scanf("%d%d", &q[i].l, &q[i].r), q[i].id = i;
    sort(q + 1, q + m + 1);
    int r=1;
    for (int i=1;i<=m;i++) {
        while(r<=q[i].r) ins(r++);
        ans[q[i].id]=query(q[i].l);
        //printf("%d %d %d %d %d\n",i,r,q[i].l,q[i].r,q[i].id);
        //for(int j=0;j<3;j++) printf("%d %d %d\n",j,p[j],pos[j]);
    }
    for(int i=1;i<=m;i++) printf("%d\n",ans[i]);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define mem(a) memset(a,0,sizeof(a))
#define sqr(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int mn = 5e5 + 5;

int n, m;
int a[mn], p[25], pos[25];

void ins(int i) {
    int id=i,x=a[i];
    for (int j = 21; j >= 0; j--) {
        if (!(x >> j)) continue;  //对线性基的这一位没有贡献
        if (!p[j]) {
            p[j] = x;
            pos[j] = id;
            break;
        }  //选入线性基中
        swap(x,p[j]);
        swap(id,pos[j]);
        x^=p[j];
    };
    for(int j=0;j<3;j++) printf("%d!%d %d %d\n",i,j,p[j],pos[j]);
}

int query(int l){
    int ans=0;
    for (int j = 21; j >= 0; j--) {
        if (p[j]&&pos[j]>=l&&(ans^p[j])>ans) ans^=p[j];
        //printf("!%d %d %d %d\n",j,ans,pos[j],l);
    }
    return ans;
}

struct query {
    int l, r, id;
    bool operator<(const query &p) const {
        return r < p.r;
    }
} q[mn];

int ans[mn];

int main() {
#ifdef trote
    freopen("../1.txt", "r", stdin);
#endif
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    scanf("%d", &m);
    for (int i = 1; i <= m; i++) scanf("%d%d", &q[i].l, &q[i].r), q[i].id = i;
    sort(q + 1, q + m + 1);
    int r=1;
    for (int i=1;i<=m;i++) {
        while(r<=q[i].r) ins(r++);
        ans[q[i].id]=query(q[i].l);
        printf("%d %d %d %d %d\n",i,r,q[i].l,q[i].r,q[i].id);
        for(int j=0;j<3;j++) printf("%d %d %d\n",j,p[j],pos[j]);
    }
    for(int i=1;i<=m;i++) printf("%d\n",ans[i]);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define mem(a) memset(a,0,sizeof(a))
#define sqr(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

const int mn = 5e5 + 5;

int n, m;
int a[mn], p[25], pos[25];

void ins(int i) {
	for (int j = 21; j >= 0; j--) {
		if (!(a[i] >> j)) continue;  //对线性基的这一位没有贡献
		if (!p[j]) {
			p[j] = a[i];
			pos[j] = i;
			break;
		}  //选入线性基中
		if (pos[j]<i) pos[j]=i,p[j]=a[i];
		a[i] ^= p[j];
	}
}

int query(int l){
	int ans=0;
	for (int j = 21; j >= 0; j--) {
		if (p[j]&&pos[j]>=l&&(ans^p[j])>ans) ans^=p[j];
		//printf("!%d %d %d %d\n",j,ans,pos[j],l);
	}
	return ans;
}

struct query {
	int l, r, id;
	bool operator<(const query &p) const {
		return r < p.r;
	}
} q[mn];

int ans[mn];

int main() {
#ifdef LOCAL
	freopen("../1.txt", "r", stdin);
#endif
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	scanf("%d", &m);
	for (int i = 1; i <= m; i++) scanf("%d%d", &q[i].l, &q[i].r), q[i].id = i;
	sort(q + 1, q + m + 1);
	int r=1;
	for (int i=1;i<=m;i++) {
		while(r<=q[i].r) ins(r++);
		ans[q[i].id]=query(q[i].l);
		//printf("%d %d %d %d %d\n",i,r,q[i].l,q[i].r,q[i].id);
		//for(int j=0;j<3;j++) printf("%d %d %d\n",j,p[j],pos[j]);
	}
	for(int i=1;i<=m;i++) printf("%d\n",ans[i]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 500005, LG = 20;

int n, q, l, r, a[N];
vector<int> ans;

inline vector<int> operator+(const vector<int> &a, const vector<int> &b)
{
    vector<int> ans = a;
    for (int u : b)
    {
        for (int i = LG - 1; i >= 0; i--)
            if ((u >> i & 1) && (u ^= ans[i]) == 0)
                break;
        if (u != 0)
            ans[31 - __builtin_clz(u)] = u;
    }
    return ans;
}

class CTree
{
#define m (l + r) / 2
#define lc i * 2
#define rc i * 2 + 1

  private:
    vector<int> tr[4 * N];

  public:
    void build(int l, int r, int i)
    {
        if (l == r)
        {
            tr[i] = vector<int>(LG, 0);
            if (a[l] != 0)
                tr[i][31 - __builtin_clz(a[l])] = a[l];
            return;
        }
        build(l, m, lc);
        build(m + 1, r, rc);
        tr[i] = tr[lc] + tr[rc];
    }

    vector<int> que(int l, int r, int i, int L, int R)
    {
        if (l > R || r < L)
            return vector<int>(LG, 0);
        if (L <= l && r <= R)
            return tr[i];
        return que(l, m, lc, L, R) + que(m + 1, r, rc, L, R);
    }

#undef m
#undef lc
#undef rc
} seg;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", a + i);
    seg.build(1, n, 1);
    scanf("%d", &q);
    while (q--)
    {
        scanf("%d%d", &l, &r);
        ans = seg.que(1, n, 1, l, r);
        int ret = 0;
        for (int i = LG - 1; i >= 0; i--)
            ret = max(ret, ret ^ ans[i]);
        printf("%d\n", ret);
    }
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 500005, LG = 22;

int n, q, l, r, a[N];
vector<int> ans;

inline vector<int> operator+(const vector<int> &a, const vector<int> &b)
{
    vector<int> ans = a;
    for (int u : b)
    {
        for (int i = LG - 1; i >= 0; i--)
            if (u >> i & 1)
                u ^= ans[i];
        if (u != 0)
            ans[31 - __builtin_clz(u)] = u;
    }
    return ans;
}

class CTree
{
#define m (l + r) / 2
#define lc i * 2
#define rc i * 2 + 1

  private:
    vector<int> tr[4 * N];

  public:
    void build(int l, int r, int i)
    {
        if (l == r)
        {
            tr[i] = vector<int>(LG, 0);
            tr[i][31 - __builtin_clz(a[l])] = a[l];
            return;
        }
        build(l, m, lc);
        build(m + 1, r, rc);
        tr[i] = tr[lc] + tr[rc];
    }

    vector<int> que(int l, int r, int i, int L, int R)
    {
        if (l > R || r < L)
            return vector<int>(LG, 0);
        if (L <= l && r <= R)
            return tr[i];
        return que(l, m, lc, L, R) + que(m + 1, r, rc, L, R);
    }

#undef m
#undef lc
#undef rc
} seg;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", a + i);
    seg.build(1, n, 1);
    scanf("%d", &q);
    while (q--)
    {
        scanf("%d%d", &l, &r);
        ans = seg.que(1, n, 1, l, r);
        int ret = 0;
        for (int i = LG - 1; i >= 0; i--)
            ret = max(ret, ret ^ ans[i]);
        printf("%d\n", ret);
    }
}


#include <iostream>
#include <cstdio>
#include <vector>
#define fi first
#define se second
using namespace std;

const int N = 500005, Q = 500005, LG = 20;

int n, q, l, r, a[N], ans[Q];
pair<int, int> f[LG];
vector<pair<int, int>> que[N];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", a + i);
    scanf("%d", &q);
    for (int i = 1; i <= q; i++)
    {
        scanf("%d%d", &l, &r);
        que[r].push_back(make_pair(l, i));
    }
    for (int i = 1; i <= n; i++)
    {
        pair<int, int> cur = {a[i], i};
        for (int j = LG - 1; j >= 0; j--)
            if (cur.fi >> j & 1)
            {
                if (f[j].fi == 0)
                {
                    f[j] = cur;
                    break;
                }
                else if (f[j].se < cur.se)
                    swap(f[j], cur);
                cur.fi ^= f[j].fi;
            }
        for (pair<int, int> &v : que[i])
            for (int j = LG - 1; j >= 0; j--)
                if (f[j].se >= v.fi)
                    ans[v.se] = max(ans[v.se], ans[v.se] ^ f[j].fi);
    }
    for (int i = 1; i <= q; i++)
        printf("%d\n", ans[i]);
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 500005, LG = 20;

int n, q, l, r, a[N];
vector<int> ans;

inline vector<int> operator+(const vector<int> &a, const vector<int> &b)
{
    vector<int> ans = a;
    for (int u : b)
    {
        for (int i = LG - 1; i >= 0; i--)
            if (u >> i & 1)
                u ^= a[i];
        if (u != 0)
            ans[31 - __builtin_clz(u)] = u;
    }
    return ans;
}

class CTree
{
#define m (l + r) / 2
#define lc i * 2
#define rc i * 2 + 1

  private:
    vector<int> tr[4 * N];

  public:
    void build(int l, int r, int i)
    {
        if (l == r)
        {
            tr[i] = vector<int>(LG, 0);
            tr[i][31 - __builtin_clz(a[l])] = a[l];
            return;
        }
        build(l, m, lc);
        build(m + 1, r, rc);
        tr[i] = tr[lc] + tr[rc];
    }

    vector<int> que(int l, int r, int i, int L, int R)
    {
        if (l > R || r < L)
            return vector<int>(LG, 0);
        if (L <= l && r <= R)
            return tr[i];
        return que(l, m, lc, L, R) + que(m + 1, r, rc, L, R);
    }

#undef m
#undef lc
#undef rc
} seg;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", a + i);
    seg.build(1, n, 1);
    scanf("%d", &q);
    while (q--)
    {
        scanf("%d%d", &l, &r);
        ans = seg.que(1, n, 1, l, r);
        int ret = 0;
        for (int i = LG - 1; i >= 0; i--)
            ret = max(ret, ret ^ ans[i]);
        printf("%d\n", ret);
    }
}


#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

const int N = 500005;

int n, q, l, r, a[N];
set<int, greater<int>> ans;

inline set<int, greater<int>> operator+(const set<int, greater<int>> &a, const set<int, greater<int>> &b)
{
    set<int, greater<int>> ans;
    for (int v : a)
        ans.insert(v);
    for (int u : b)
    {
        for (int v : ans)
            if (u >> (31 - __builtin_clz(v)) & 1)
                u ^= v;
        if (u != 0)
            ans.insert(u);
    }
    return ans;
}

class CTree
{
#define m (l + r) / 2
#define lc i * 2
#define rc i * 2 + 1

  private:
    set<int, greater<int>> tr[4 * N];

  public:
    void build(int l, int r, int i)
    {
        if (l == r)
        {
            tr[i].insert(a[l]);
            return;
        }
        build(l, m, lc);
        build(m + 1, r, rc);
        tr[i] = tr[lc] + tr[rc];
    }

    set<int, greater<int>> query(int l, int r, int i, int L, int R)
    {
        if (l > R || r < L)
            return {};
        if (L <= l && r <= R)
            return tr[i];
        return query(l, m, lc, L, R) + query(m + 1, r, rc, L, R);
    }

#undef m
#undef lc
#undef rc
} seg;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", a + i);
    seg.build(1, n, 1);
    scanf("%d", &q);
    while (q--)
    {
        scanf("%d%d", &l, &r);
        ans = seg.query(1, n, 1, l, r);
        int ret = 0;
        for (int u : ans)
            ret = max(ret, ret ^ u);
        printf("%d\n", ret);
    }
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 500005, LG = 20;

int n, q, l, r, a[N];
vector<int> ans;

inline vector<int> operator+(const vector<int> &a, const vector<int> &b)
{
    vector<int> ans = a;
    for (int u : b)
    {
        for (int i = LG - 1; i >= 0; i--)
            if (u >> i & 1)
                u ^= ans[i];
        if (u != 0)
            ans[31 - __builtin_clz(u)] = u;
    }
    return ans;
}

class CTree
{
#define m (l + r) / 2
#define lc i * 2
#define rc i * 2 + 1

  private:
    vector<int> tr[4 * N];

  public:
    void build(int l, int r, int i)
    {
        if (l == r)
        {
            tr[i] = vector<int>(LG, 0);
            if (a[l] != 0)
                tr[i][31 - __builtin_clz(a[l])] = a[l];
            return;
        }
        build(l, m, lc);
        build(m + 1, r, rc);
        tr[i] = tr[lc] + tr[rc];
    }

    vector<int> que(int l, int r, int i, int L, int R)
    {
        if (l > R || r < L)
            return vector<int>(LG, 0);
        if (L <= l && r <= R)
            return tr[i];
        return que(l, m, lc, L, R) + que(m + 1, r, rc, L, R);
    }

#undef m
#undef lc
#undef rc
} seg;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", a + i);
    seg.build(1, n, 1);
    scanf("%d", &q);
    while (q--)
    {
        scanf("%d%d", &l, &r);
        ans = seg.que(1, n, 1, l, r);
        int ret = 0;
        for (int i = LG - 1; i >= 0; i--)
            ret = max(ret, ret ^ ans[i]);
        printf("%d\n", ret);
    }
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int N = 500005, LG = 20;

int n, q, l, r, buc[1 << LG], a[N];
vector<int> ans;

inline vector<int> operator+(const vector<int> &a, const vector<int> &b)
{
    vector<int> ans = a;
    for (int u : b)
        while (u != 0)
            if (ans[buc[u]] == 0)
            {
                ans[buc[u]] = u;
                break;
            }
            else
                u ^= ans[buc[u]];
    return ans;
}

class CTree
{
#define m (l + r) / 2
#define lc i * 2
#define rc i * 2 + 1

  private:
    vector<int> tr[4 * N];

  public:
    void build(int l, int r, int i)
    {
        if (l == r)
        {
            tr[i] = vector<int>(LG, 0);
            if (a[l] != 0)
                tr[i][buc[a[l]]] = a[l];
            return;
        }
        build(l, m, lc);
        build(m + 1, r, rc);
        tr[i] = tr[lc] + tr[rc];
    }

    vector<int> que(int l, int r, int i, int L, int R)
    {
        if (l > R || r < L)
            return vector<int>(LG, 0);
        if (L <= l && r <= R)
            return tr[i];
        return que(l, m, lc, L, R) + que(m + 1, r, rc, L, R);
    }

#undef m
#undef lc
#undef rc
} seg;

int main()
{
    for (int i = 1; i < (1 << LG); i++)
        buc[i] = 31 - __builtin_clz(i);
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%d", a + i);
    seg.build(1, n, 1);
    scanf("%d", &q);
    while (q--)
    {
        scanf("%d%d", &l, &r);
        ans = seg.que(1, n, 1, l, r);
        int ret = 0;
        for (int i = LG - 1; i >= 0; i--)
            ret = max(ret, ret ^ ans[i]);
        printf("%d\n", ret);
    }
}


#include <bits/stdc++.h>
using namespace std;

#define N 500010
#define M 10010
#define S 300
int n, q, c[N];
int p[M][25], pos[N], lpos[M], rpos[M];

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i) pos[i] = (i - 1) / S + 1;
		for (int i = 1; i <= n; ++i)
		{
			rpos[pos[i]] = i;
			if (i == 1 || pos[i] != pos[i - 1])
				lpos[pos[i]] = i;

		}
		for (int i = 1; i <= n; ++i) scanf("%d", c + i);
		[]()
		{
			memset(p, 0, sizeof p);
			for (int i = 1; i <= pos[n]; ++i)
			{
				for (int j = lpos[i]; j <= rpos[i]; ++j)
				{
					int tmp = c[j];
					for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
					{
						if (!p[i][k])
						{
							p[i][k] = tmp;
							break;
						}
						else
							tmp ^= p[i][k];
						if (!tmp) break;
					}
				}
			}
		}();
		scanf("%d", &q);
		for (int qq = 1, l, r; qq <= q; ++qq)
		{
			scanf("%d%d", &l, &r);
			printf("%d\n", [](int l, int r)
			{
				int pp[25];
			    memset(pp, 0, sizeof pp);
				if (pos[l] == pos[r])
				{
					for (int i = l; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
				}
				else
				{
					for (int i = l; i <= rpos[pos[l]]; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = lpos[pos[r]]; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = pos[l] + 1; i < pos[r]; ++i)
					{
						for (int j = 20; j >= 0; --j)
						{
							int tmp = p[i][j];
							for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
							{
								if (!pp[k])
								{
									pp[k] = tmp;
									break;
								}
								else
									tmp ^= pp[k];
								if (!tmp) break;
							}
						}
					}
				}
				int res = 0;
				for (int i = 20; i >= 0; --i) if ((res ^ pp[i]) > res)
					res ^= pp[i];
				//cout << res << endl;
				return res;
			}(l, r));
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define N 500010
int n, q, c[N];
int pos[N][25], p[N][25];

void work(int x)
{
	for (int i = 0; i <= 20; ++i)
	{
		pos[x][i] = pos[x - 1][i];
		p[x][i] = p[x - 1][i];
	}
	for (int i = 20; i >= 0; --i)
	{
		int tmp = c[x];
		int id = x;
		if ((tmp >> i) & 1)
		{
			if (!p[x][i])
			{
				p[x][i] = tmp;
				pos[x][i] = id;
				return;
			}
			if (pos[x][i] < id)
			{
				swap(tmp, p[x][i]);
				swap(id, pos[x][i]);
			}
			tmp ^= p[x][i];
		}
	}
}

int ask(int l, int r)
{
	int res = 0;
	for (int i = 20; i >= 0; --i) if (pos[r][i] >= l && (res ^ p[r][i]) > res)
		res ^= p[r][i];
	return res;
}

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i) scanf("%d", c + i);
		for (int i = 0; i < 25; ++i) pos[0][i] = p[0][i] = 0;
		for (int i = 1; i <= n; ++i) work(i);
		scanf("%d", &q);
		for (int qq = 1, l, r; qq <= q; ++qq)
		{
			scanf("%d%d", &l, &r);
			printf("%d\n", ask(l, r));
		}

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define N 500010
#define S 3000
int n, q, c[N];
int p[S][25], pos[N], lpos[S], rpos[S];

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i) pos[i] = (i - 1) / S + 1;
		for (int i = 1; i <= pos[n]; ++i)
		{
			rpos[pos[i]] = i;
			if (i == 1 || pos[i] != pos[i - 1])
				lpos[pos[i]] = i;

		}
		for (int i = 1; i <= n; ++i) scanf("%d", c + i);
		[]()
		{
			memset(p, 0, sizeof p);
			for (int i = 1; i <= pos[n]; ++i)
			{
				for (int j = lpos[i]; j <= rpos[i]; ++j)
				{
					int tmp = c[j];
					for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
					{
						if (!p[k])
						{
							p[i][k] = tmp;
							break;
						}
						else
							tmp ^= p[i][k];
						if (!tmp) break;
					}
				}
			}
		}();
		scanf("%d", &q);
		for (int qq = 1, l, r; qq <= q; ++qq)
		{
			scanf("%d%d", &l, &r);
			printf("%d\n", [](int l, int r)
			{
				int pp[25];
			    memset(pp, 0, sizeof pp);
				if (pos[l] == pos[r])
				{
					for (int i = l; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
				}
				else
				{
					for (int i = l; i <= rpos[pos[l]]; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = lpos[pos[r]]; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = pos[l] + 1; i < pos[r]; ++i)
					{
						for (int j = 20; j >= 0; --j) if (p[i][j])
						{
							int tmp = p[i][j];
							for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
							{
								if (!pp[k])
								{
									pp[k] = tmp;
									break;
								}
								else
									tmp ^= pp[k];
								if (!tmp) break;
							}
						}
					}
				}
				int res = 0;
				for (int i = 20; i >= 0; --i) if ((res ^ pp[i]) > res)
					res ^= pp[i];
				//cout << res << endl;
				return res;
			}(l, r));
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define N 500010
#define M 10010
#define S 10010
int n, q, c[N];
int p[M][25], pos[N], lpos[M], rpos[M];

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i) pos[i] = (i - 1) / S + 1;
		for (int i = 1; i <= n; ++i)
		{
			rpos[pos[i]] = i;
			if (i == 1 || pos[i] != pos[i - 1])
				lpos[pos[i]] = i;

		}
		for (int i = 1; i <= n; ++i) scanf("%d", c + i);
		[]()
		{
			memset(p, 0, sizeof p);
			for (int i = 1; i <= pos[n]; ++i)
			{
				for (int j = lpos[i]; j <= rpos[i]; ++j)
				{
					int tmp = c[j];
					for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
					{
						if (!p[i][k])
						{
							p[i][k] = tmp;
							break;
						}
						else
							tmp ^= p[i][k];
						if (!tmp) break;
					}
				}
			}
		}();
		scanf("%d", &q);
		for (int qq = 1, l, r; qq <= q; ++qq)
		{
			scanf("%d%d", &l, &r);
			printf("%d\n", [](int l, int r)
			{
				int pp[25];
			    memset(pp, 0, sizeof pp);
				if (pos[l] == pos[r])
				{
					for (int i = l; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
				}
				else
				{
					cout << rpos[pos[l]] << " " << lpos[pos[r]] << endl;
					for (int i = l; i <= rpos[pos[l]]; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = lpos[pos[r]]; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = pos[l] + 1; i < pos[r]; ++i)
					{
						for (int j = 20; j >= 0; --j)
						{
							int tmp = p[i][j];
							for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
							{
								if (!pp[k])
								{
									pp[k] = tmp;
									break;
								}
								else
									tmp ^= pp[k];
								if (!tmp) break;
							}
						}
					}
				}
				int res = 0;
				for (int i = 20; i >= 0; --i) if ((res ^ pp[i]) > res)
					res ^= pp[i];
				//cout << res << endl;
				return res;
			}(l, r));
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define N 500010
#define M 10010
#define S 5
int n, q, c[N];
int p[M][25], pos[N], lpos[M], rpos[M];

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i) pos[i] = (i - 1) / S + 1;
		for (int i = 1; i <= pos[n]; ++i)
		{
			rpos[pos[i]] = i;
			if (i == 1 || pos[i] != pos[i - 1])
				lpos[pos[i]] = i;

		}
		for (int i = 1; i <= n; ++i) scanf("%d", c + i);
		[]()
		{
			memset(p, 0, sizeof p);
			for (int i = 1; i <= pos[n]; ++i)
			{
				for (int j = lpos[i]; j <= rpos[i]; ++j)
				{
					int tmp = c[j];
					for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
					{
						if (!p[i][k])
						{
							p[i][k] = tmp;
							break;
						}
						else
							tmp ^= p[i][k];
						if (!tmp) break;
					}
				}
			}
		}();
		scanf("%d", &q);
		for (int qq = 1, l, r; qq <= q; ++qq)
		{
			scanf("%d%d", &l, &r);
			printf("%d\n", [](int l, int r)
			{
				int pp[25];
			    memset(pp, 0, sizeof pp);
				if (pos[l] == pos[r])
				{
					for (int i = l; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
				}
				else
				{
					for (int i = l; i <= rpos[pos[l]]; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = lpos[pos[r]]; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = pos[l] + 1; i < pos[r]; ++i)
					{
						for (int j = 20; j >= 0; --j)
						{
							int tmp = p[i][j];
							for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
							{
								if (!pp[k])
								{
									pp[k] = tmp;
									break;
								}
								else
									tmp ^= pp[k];
								if (!tmp) break;
							}
						}
					}
				}
				int res = 0;
				for (int i = 20; i >= 0; --i) if ((res ^ pp[i]) > res)
					res ^= pp[i];
				//cout << res << endl;
				return res;
			}(l, r));
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define N 500010
#define M 10010
#define S 450
int n, q, c[N];
int p[M][25], pos[N], lpos[M], rpos[M];

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i) pos[i] = (i - 1) / S + 1;
		for (int i = 1; i <= n; ++i)
		{
			rpos[pos[i]] = i;
			if (i == 1 || pos[i] != pos[i - 1])
				lpos[pos[i]] = i;

		}
		for (int i = 1; i <= n; ++i) scanf("%d", c + i);
		[]()
		{
			memset(p, 0, sizeof p);
			for (int i = 1; i <= pos[n]; ++i)
			{
				for (int j = lpos[i]; j <= rpos[i]; ++j)
				{
					int tmp = c[j];
					for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
					{
						if (!p[i][k])
						{
							p[i][k] = tmp;
							break;
						}
						else
							tmp ^= p[i][k];
						if (!tmp) break;
					}
				}
			}
		}();
		scanf("%d", &q);
		for (int qq = 1, l, r; qq <= q; ++qq)
		{
			scanf("%d%d", &l, &r);
			printf("%d\n", [](int l, int r)
			{
				int pp[25];
			    memset(pp, 0, sizeof pp);
				if (pos[l] == pos[r])
				{
					for (int i = l; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
				}
				else
				{
					for (int i = l; i <= rpos[pos[l]]; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = lpos[pos[r]]; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = pos[l] + 1; i < pos[r]; ++i)
					{
						for (int j = 20; j >= 0; --j)
						{
							int tmp = p[i][j];
							for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
							{
								if (!pp[k])
								{
									pp[k] = tmp;
									break;
								}
								else
									tmp ^= pp[k];
								if (!tmp) break;
							}
						}
					}
				}
				int res = 0;
				for (int i = 20; i >= 0; --i) if ((res ^ pp[i]) > res)
					res ^= pp[i];
				//cout << res << endl;
				return res;
			}(l, r));
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define N 500010
int n, q, c[N];
int pos[N][25], p[N][25];

void work(int x)
{
	for (int i = 0; i <= 20; ++i)
	{
		pos[x][i] = pos[x - 1][i];
		p[x][i] = pos[x - 1][i];
	}
	for (int i = 20; i >= 0; --i)
	{
		int tmp = c[x];
		int id = x;
		if ((tmp >> i) & 1)
		{
			if (!p[x][i])
			{
				p[x][i] = tmp;
				pos[x][i] = id;
				return;
			}
			if (pos[x][i] < id)
			{
				swap(tmp, p[x][i]);
				swap(id, pos[x][i]);
			}
			tmp ^= p[x][i];
		}
	}
}

int ask(int l, int r)
{
	int res = 0;
	for (int i = 20; i >= 0; --i) if (pos[r][i] >= l && (res ^ p[r][i]) > res)
		res ^= p[r][i];
	return res;
}

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i) scanf("%d", c + i);
		for (int i = 0; i < 25; ++i) pos[0][i] = p[0][i] = 0;
		for (int i = 1; i <= n; ++i) work(i);
		scanf("%d", &q);
		for (int qq = 1, l, r; qq <= q; ++qq)
		{
			scanf("%d%d", &l, &r);
			printf("%d\n", ask(l, r));
		}

	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define N 500010
#define M 10010
#define S 300
int n, q, c[N];
int p[M][25], pos[N], lpos[M], rpos[M];

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i) pos[i] = (i - 1) / S + 1;
		for (int i = 1; i <= pos[n]; ++i)
		{
			rpos[pos[i]] = i;
			if (i == 1 || pos[i] != pos[i - 1])
				lpos[pos[i]] = i;

		}
		for (int i = 1; i <= n; ++i) scanf("%d", c + i);
		[]()
		{
			memset(p, 0, sizeof p);
			for (int i = 1; i <= pos[n]; ++i)
			{
				for (int j = lpos[i]; j <= rpos[i]; ++j)
				{
					int tmp = c[j];
					for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
					{
						if (!p[i][k])
						{
							p[i][k] = tmp;
							break;
						}
						else
							tmp ^= p[i][k];
						if (!tmp) break;
					}
				}
			}
		}();
		scanf("%d", &q);
		for (int qq = 1, l, r; qq <= q; ++qq)
		{
			scanf("%d%d", &l, &r);
			printf("%d\n", [](int l, int r)
			{
				int pp[25];
			    memset(pp, 0, sizeof pp);
				if (pos[l] == pos[r])
				{
					for (int i = l; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
				}
				else
				{
					for (int i = l; i <= rpos[pos[l]]; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = lpos[pos[r]]; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = pos[l] + 1; i < pos[r]; ++i)
					{
						for (int j = 20; j >= 0; --j) if (p[i][j])
						{
							int tmp = p[i][j];
							for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
							{
								if (!pp[k])
								{
									pp[k] = tmp;
									break;
								}
								else
									tmp ^= pp[k];
								if (!tmp) break;
							}
						}
					}
				}
				int res = 0;
				for (int i = 20; i >= 0; --i) if ((res ^ pp[i]) > res)
					res ^= pp[i];
				//cout << res << endl;
				return res;
			}(l, r));
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define N 500010
#define M 10010
#define S 200
int n, q, c[N];
int p[M][25], pos[N], lpos[M], rpos[M];

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i) pos[i] = (i - 1) / S + 1;
		for (int i = 1; i <= n; ++i)
		{
			rpos[pos[i]] = i;
			if (i == 1 || pos[i] != pos[i - 1])
				lpos[pos[i]] = i;

		}
		for (int i = 1; i <= n; ++i) scanf("%d", c + i);
		[]()
		{
			memset(p, 0, sizeof p);
			for (int i = 1; i <= pos[n]; ++i)
			{
				for (int j = lpos[i]; j <= rpos[i]; ++j)
				{
					int tmp = c[j];
					for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
					{
						if (!p[i][k])
						{
							p[i][k] = tmp;
							break;
						}
						else
							tmp ^= p[i][k];
						if (!tmp) break;
					}
				}
			}
		}();
		scanf("%d", &q);
		for (int qq = 1, l, r; qq <= q; ++qq)
		{
			scanf("%d%d", &l, &r);
			printf("%d\n", [](int l, int r)
			{
				int pp[25];
			    memset(pp, 0, sizeof pp);
				if (pos[l] == pos[r])
				{
					for (int i = l; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
				}
				else
				{
					for (int i = l; i <= rpos[pos[l]]; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = lpos[pos[r]]; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = pos[l] + 1; i < pos[r]; ++i)
					{
						for (int j = 20; j >= 0; --j)
						{
							int tmp = p[i][j];
							for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
							{
								if (!pp[k])
								{
									pp[k] = tmp;
									break;
								}
								else
									tmp ^= pp[k];
								if (!tmp) break;
							}
						}
					}
				}
				int res = 0;
				for (int i = 20; i >= 0; --i) if ((res ^ pp[i]) > res)
					res ^= pp[i];
				//cout << res << endl;
				return res;
			}(l, r));
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define N 500010
#define M 10010
#define S 300
int n, q, c[N];
int p[M][25], pos[N], lpos[M], rpos[M];

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i) pos[i] = (i - 1) / S + 1;
		for (int i = 1; i <= n; ++i)
		{
			rpos[pos[i]] = i;
			if (i == 1 || pos[i] != pos[i - 1])
				lpos[pos[i]] = i;

		}
		for (int i = 1; i <= n; ++i) scanf("%d", c + i);
		[]()
		{
			memset(p, 0, sizeof p);
			for (int i = 1; i <= pos[n]; ++i)
			{
				for (int j = lpos[i]; j <= rpos[i]; ++j)
				{
					int tmp = c[j];
					for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
					{
						if (!p[i][k])
						{
							p[i][k] = tmp;
							break;
						}
						else
							tmp ^= p[i][k];
						if (!tmp) break;
					}
				}
			}
		}();
		scanf("%d", &q);
		for (int qq = 1, l, r; qq <= q; ++qq)
		{
			scanf("%d%d", &l, &r);
			printf("%d\n", [](int l, int r)
			{
				int pp[25];
			    memset(pp, 0, sizeof pp);
				if (pos[l] == pos[r])
				{
					for (int i = l; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
				}
				else
				{
					cout << rpos[pos[l]] << " " << lpos[pos[r]] << endl;
					for (int i = l; i <= rpos[pos[l]]; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = lpos[pos[r]]; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = pos[l] + 1; i < pos[r]; ++i)
					{
						for (int j = 20; j >= 0; --j)
						{
							int tmp = p[i][j];
							for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
							{
								if (!pp[k])
								{
									pp[k] = tmp;
									break;
								}
								else
									tmp ^= pp[k];
								if (!tmp) break;
							}
						}
					}
				}
				int res = 0;
				for (int i = 20; i >= 0; --i) if ((res ^ pp[i]) > res)
					res ^= pp[i];
				//cout << res << endl;
				return res;
			}(l, r));
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define N 500010
#define S 4000
int n, q, c[N];
int p[S][25], pos[N], lpos[S], rpos[S];

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i) pos[i] = (i - 1) / S + 1;
		for (int i = 1; i <= pos[n]; ++i)
		{
			rpos[pos[i]] = i;
			if (i == 1 || pos[i] != pos[i - 1])
				lpos[pos[i]] = i;

		}
		for (int i = 1; i <= n; ++i) scanf("%d", c + i);
		[]()
		{
			memset(p, 0, sizeof p);
			for (int i = 1; i <= pos[n]; ++i)
			{
				for (int j = lpos[i]; j <= rpos[i]; ++j)
				{
					int tmp = c[j];
					for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
					{
						if (!p[k])
						{
							p[i][k] = tmp;
							break;
						}
						else
							tmp ^= p[i][k];
						if (!tmp) break;
					}
				}
			}
		}();
		scanf("%d", &q);
		for (int qq = 1, l, r; qq <= q; ++qq)
		{
			scanf("%d%d", &l, &r);
			printf("%d\n", [](int l, int r)
			{
				int pp[25];
			    memset(pp, 0, sizeof pp);
				if (pos[l] == pos[r])
				{
					for (int i = l; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
				}
				else
				{
					for (int i = l; i <= rpos[pos[l]]; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = lpos[pos[r]]; i <= r; ++i)
					{
						int tmp = c[i];
						for (int j = 20; j >= 0; --j) if ((tmp >> j) & 1)
						{
							if (!pp[j])
							{
								pp[j] = tmp;
								break;
							}
							else
								tmp ^= pp[j];
							if (!tmp) break;
						}
					}
					for (int i = pos[l] + 1; i < pos[r]; ++i)
					{
						for (int j = 20; j >= 0; --j) if (p[i][j])
						{
							int tmp = p[i][j];
							for (int k = 20; k >= 0; --k) if ((tmp >> k) & 1)
							{
								if (!pp[k])
								{
									pp[k] = tmp;
									break;
								}
								else
									tmp ^= pp[k];
								if (!tmp) break;
							}
						}
					}
				}
				int res = 0;
				for (int i = 20; i >= 0; --i) if ((res ^ pp[i]) > res)
					res ^= pp[i];
				//cout << res << endl;
				return res;
			}(l, r));
		}
	}
	return 0;
}