#include <bits/stdc++.h>
using namespace std;
struct data {
  int l;
  int r;
  int id;
} q[500060];
int n, m, a[500060], ji[20 + 5], cnt, ans[500060], pos[20 + 5], pp;
int readi() {
  int x = 0;
  char c;
  int w = 1;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') w = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= w;
  return x;
}
long long readl() {
  long long x = 0;
  char c;
  long long w = 1;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') w = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= w;
  return x;
}
void readint(int& x) {
  x = 0;
  char c;
  int w = 1;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') w = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= w;
}
void readlong(long long& x) {
  x = 0;
  char c;
  long long w = 1;
  for (c = getchar(); c < '0' || c > '9'; c = getchar())
    if (c == '-') w = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) x = (x << 3) + (x << 1) + c - '0';
  x *= w;
}
bool file_link() {
  bool ___ = freopen("input.txt", "r", stdin);
  bool ____ = freopen("output.txt", "w", stdout);
  if (!(___ & ____)) {
    puts("找不到对象!");
    return false;
  }
  return true;
}
bool cmp(const struct data a, const struct data b) { return (a.r < b.r); }
int main() {
  readint(n);
  for (int i = (1); i <= (n); ++i) readint(a[i]);
  readint(m);
  for (int i = (1); i <= (m); ++i) {
    readint(q[i].l);
    readint(q[i].r);
    q[i].id = i;
  }
  sort(q + 1, q + 1 + m, cmp);
  cnt = 1;
  for (int i = (1); i <= (n); ++i) {
    pp = i;
    for (int j = (20); j >= (0); --j)
      if (a[i] & (1 << j))
        if (!ji[j]) {
          ji[j] = a[i];
          pos[j] = pp;
          break;
        } else {
          if (pp > pos[j]) {
            swap(pp, pos[j]);
            swap(a[i], ji[j]);
          }
          a[i] ^= ji[j];
        }
    while (i == q[cnt].r) {
      for (int j = (20); j >= (0); --j)
        if (pos[j] >= q[cnt].l)
          ans[q[cnt].id] = (((ans[q[cnt].id]) > (ans[q[cnt].id] ^ ji[j])
                                 ? (ans[q[cnt].id])
                                 : (ans[q[cnt].id] ^ ji[j])));
      ++cnt;
    }
  }
  for (int i = (1); i <= (m); ++i) printf("%d\n", ans[i]);
  return 0;
}
