#include <bits/stdc++.h>
using namespace std;
const int LG = 21;
const int M = 1000;
const int N = 500010;
const int V = 1000010;
int n, q, a[N], store[N], tmp[LG][M], cur[LG], msb[V];
int suff[N][LG], pref[N][LG], suff_sz[N], pref_sz[N];
void gauss() {
  for (int i = LG - 1; i >= 0; --i) {
    if (cur[i] == 0) continue;
    int yo, nxt;
    for (int j = 1; j < cur[i]; ++j) {
      if (tmp[i][j] != tmp[i][0]) {
        yo = tmp[i][j] ^ tmp[i][0], nxt = msb[yo];
        tmp[nxt][cur[nxt]++] = yo;
      }
    }
    cur[i] = 1;
  }
}
void solve(int l, int r, vector<tuple<int, int, int> > v) {
  if (v.empty()) return;
  if (l == r) {
    for (auto it : v) {
      store[get<2>(it)] = a[l];
    }
    return;
  }
  int mid = l + r >> 1, x, y, z;
  vector<tuple<int, int, int> > one, two, now;
  for (auto it : v) {
    tie(x, y, z) = it;
    if (y <= mid)
      one.push_back(it);
    else if (x > mid)
      two.push_back(it);
    else
      now.push_back(it);
  }
  solve(l, mid, one), solve(mid + 1, r, two);
  for (int i = 0; i < LG; ++i) cur[i] = 0;
  for (int i = mid; i >= l; --i) {
    int yo = a[i], nxt = msb[yo];
    if (yo) tmp[nxt][cur[nxt]++] = yo;
    gauss();
    suff_sz[i] = 0;
    for (int j = 0; j < LG; ++j) {
      if (cur[j]) suff[i][suff_sz[i]++] = tmp[j][0];
    }
  }
  for (int i = 0; i < LG; ++i) cur[i] = 0;
  for (int i = mid + 1; i <= r; ++i) {
    int yo = a[i], nxt = msb[yo];
    if (yo) tmp[nxt][cur[nxt]++] = yo;
    gauss();
    pref_sz[i] = 0;
    for (int j = 0; j < LG; ++j) {
      if (cur[j]) pref[i][pref_sz[i]++] = tmp[j][0];
    }
  }
  for (auto it : now) {
    int x, y, z;
    tie(x, y, z) = it;
    for (int i = 0; i < LG; ++i) cur[i] = 0;
    for (int i = 0; i < suff_sz[x]; ++i) {
      int yo = suff[x][i], nxt = msb[yo];
      if (yo) tmp[nxt][cur[nxt]++] = yo;
    }
    for (int i = 0; i < pref_sz[y]; ++i) {
      int yo = pref[y][i], nxt = msb[yo];
      if (yo) tmp[nxt][cur[nxt]++] = yo;
    }
    gauss();
    int ans = 0;
    for (int i = LG - 1; i >= 0; --i) {
      if (cur[i]) ans = max(ans, ans ^ tmp[i][0]);
    }
    store[z] = ans;
  }
}
int main() {
  for (int i = 1; i < V; ++i) {
    for (int j = LG; j >= 0; --j) {
      if (i & 1 << j) {
        msb[i] = j;
        break;
      }
    }
  }
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  cin >> q;
  vector<tuple<int, int, int> > v;
  for (int i = 0; i < q; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);
    v.emplace_back(l, r, i);
  }
  solve(1, n, v);
  for (int i = 0; i < q; ++i) {
    printf("%d\n", store[i]);
  }
  return 0;
}
