#include <bits/stdc++.h>
using namespace std;
const int N = 500005, K = 32;
vector<pair<int, int> > ve[N];
vector<pair<int, int> >::iterator it;
int n, m, t1, t2, val[N], ans[N], bas[K], pos[K];
void Insert(int x, int y) {
  for (int i = 21; ~i; i--)
    if (x & (1 << i)) {
      if (!bas[i]) {
        bas[i] = x, pos[i] = y;
        return;
      }
      if (y > pos[i]) swap(x, bas[i]), swap(y, pos[i]);
      x ^= bas[i];
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &val[i]);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &t1, &t2);
    ve[t2].push_back(make_pair(t1, i));
  }
  for (int i = 1; i <= n; i++) {
    Insert(val[i], i);
    for (it = ve[i].begin(); it != ve[i].end(); it++) {
      int lef = it->first, idx = it->second;
      for (int j = 21; ~j; j--)
        if (pos[j] >= lef && (ans[idx] ^ bas[j]) > ans[idx]) ans[idx] ^= bas[j];
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
