#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int s = 0, t = 0;
  register char ch = getchar();
  while (ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9')
    s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return t ? -s : s;
}
struct node {
  int x, y, id;
} b[500001];
int a[500001], L[500001], id[500001], sum[500001], d[500001][21], m, cnt,
    ans[500001], n, idx[500001], LL[500001];
void insert(int x, int id) {
  for (int i = 20; i >= 0; i--) {
    if (((1 << i) & x) == 0) continue;
    if (!d[id][i]) {
      d[id][i] = x;
      sum[id]++;
      break;
    } else
      x ^= d[id][i];
  }
}
int query(int id) {
  int s = 0;
  for (int i = 20; i >= 0; i--)
    if (d[id][i] && (s & (1 << i)) == 0) s ^= d[id][i];
  return s;
}
bool cmp(node g, node h) { return g.y < h.y; }
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  m = read();
  for (int i = 1; i <= m; i++) b[i].x = read(), b[i].y = read(), b[i].id = i;
  sort(b + 1, b + m + 1, cmp);
  for (int i = 1; i <= n; i++) L[i] = i, id[i] = i;
  int nowx = 1;
  id[n + 1] = n + 1;
  for (int i = 1; i <= n; i++) {
    if (a[i] != 0) {
      id[cnt + 1] = i;
      cnt++;
      L[cnt] = i;
      for (int j = 1; j <= cnt; j++) insert(a[i], id[j]);
      int now = n + 1, cntx = 0;
      for (int j = cnt; j >= 1; j--) {
        if (sum[id[j]] == sum[id[now]])
          LL[cntx] = L[j];
        else
          cntx++, idx[cntx] = id[j], now = j, LL[cntx] = L[j];
      }
      cnt = cntx;
      for (int j = 1; j <= cnt; j++) {
        id[j] = idx[cnt - j + 1];
        L[j] = LL[cnt - j + 1];
      }
      for (int j = cnt; j >= 1; j--) L[j] = id[j - 1] + 1;
    }
    while (b[nowx].y == i) {
      int x = upper_bound(L + 1, L + cnt + 1, b[nowx].x) - L - 1;
      if (id[x] < b[nowx].x)
        ans[b[nowx].id] = 0;
      else
        ans[b[nowx].id] = query(id[x]);
      nowx++;
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
}
