#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long INF = 1ll << 60;
const double Inf = 1e20;
const double eps = 1e-9;
void gmax(int &a, int b) { a = (a > b ? a : b); }
void gmin(int &a, int b) { a = (a < b ? a : b); }
const int maxn = 500050;
const int maxb = 31;
int n, c[maxn], ans[maxn];
vector<pair<int, int> > que[maxn];
int p[maxb], t[maxb];
void add(int x, int id) {
  for (int j = maxb - 1; j >= 0; --j)
    if (x & (1 << j)) {
      if (!p[j]) {
        p[j] = x;
        t[j] = id;
        break;
      } else {
        if (t[j] < id) {
          swap(t[j], id);
          swap(p[j], x);
        }
        x ^= p[j];
      }
    }
}
int ask(int id) {
  int ret = 0;
  for (int j = maxb - 1; j >= 0; --j)
    if (p[j] && t[j] >= id && (ret ^ p[j]) > ret) ret ^= p[j];
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]);
  int q, l, r;
  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) {
    add(c[i], i);
    for (auto p : que[i]) ans[p.second] = ask(p.first);
  }
  for (int i = 1; i <= q; ++i) printf("%d\n", ans[i]);
  return 0;
}
