#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const int MAXN = 500010;
int a[MAXN], ans[MAXN], p[21], ID[21], tmp[21], Cpy[21];
struct Node {
  int l, r, Id;
} q[MAXN];
struct Info {
  int x, Id;
} b[21];
inline void Ins(int x, int Id) {
  for (int i = 20; ~i; --i) {
    if (!(x & (1 << i))) continue;
    if (!p[i]) {
      p[i] = x;
      ID[i] = Id;
      break;
    }
    x ^= p[i];
  }
}
inline int Qry(int x) {
  int Ret = 0;
  for (int i = 20; ~i; --i)
    if (ID[i] >= x && (Ret ^ p[i]) > Ret) Ret ^= p[i];
  return Ret;
}
int main() {
  int N = read();
  for (int i = 1; i <= N; ++i) a[i] = read();
  int Q = read();
  for (int i = 1; i <= Q; ++i) {
    q[i].l = read();
    q[i].r = read();
    q[i].Id = i;
  }
  sort(q + 1, q + Q + 1, [&](Node a, Node b) { return a.r < b.r; });
  int Pos = 1;
  for (int i = 1; i <= Q; ++i) {
    while (Pos <= q[i].r) {
      int Len = 0;
      for (int j = 0; j <= 20; ++j)
        if (p[j]) {
          b[++Len].x = p[j];
          b[Len].Id = ID[j];
        }
      memset(p, 0, sizeof(p));
      memset(ID, 0, sizeof(ID));
      Ins(a[Pos], Pos);
      sort(b + 1, b + Len + 1, [&](Info a, Info b) { return a.Id > b.Id; });
      for (int j = 1; j <= Len; ++j) Ins(b[j].x, b[j].Id);
      ++Pos;
    }
    ans[q[i].Id] = Qry(q[i].l);
  }
  for (int i = 1; i <= Q; ++i) printf("%d\n", ans[i]);
  return 0;
}
