#include <bits/stdc++.h>
template <class T>
void PRT(const T _) {
  if (_ < 0) {
    putchar(45), PRT(-_);
    return;
  }
  if (_ >= 10) PRT(_ / 10);
  putchar(_ % 10 + 48);
}
template <class T>
void UPRT(const T _) {
  if (_ >= 10) UPRT(_ / 10);
  putchar(_ % 10 + 48);
}
using bint = unsigned;
constexpr bint ONE(1);
constexpr int MN(5e5 + 7), MB(20);
struct Node {
  int id;
  int l, r;
  inline bool operator<(const Node& o) const { return r < o.r; }
} q[MN];
bint a[MN];
int pos[MB];
bint base[MB];
bint ans[MN];
bool insert(bint v, int p) {
  for (int i = MB; i >= 0; --i) {
    if (v & (ONE << i)) {
      if (base[i]) {
        if (pos[i] < p) {
          do {
            auto _t = pos[i];
            pos[i] = p;
            p = _t;
          } while (0);
          do {
            auto _t = base[i];
            base[i] = v;
            v = _t;
          } while (0);
        }
        v ^= base[i];
      } else {
        base[i] = v;
        pos[i] = p;
        break;
      }
    }
  }
  return v;
}
bint get_max(const int l) {
  bint max = 0;
  for (int i = MB; i >= 0; --i)
    if (pos[i] >= l && (max ^ base[i]) > max) max ^= base[i];
  return max;
}
int main() {
  int n;
  {
    char _c = getchar(), _v = 1;
    for (n = 0; _c < 48 || _c > 57; _c = getchar())
      if (_c == 45) _v = -1;
    for (; _c >= 48 && _c <= 57;
         n = (n << 1) + (n << 3) + _c - 48, _c = getchar())
      ;
    if (_v == -1) n = -n;
  }
  {
    auto _i = 0, _n = n;
    for (; _i < _n; ++_i) {
      char _c = getchar(), _v = 1;
      for (a[_i] = 0; _c < 48 || _c > 57; _c = getchar())
        if (_c == 45) _v = -1;
      for (; _c >= 48 && _c <= 57;
           a[_i] = (a[_i] << 1) + (a[_i] << 3) + _c - 48, _c = getchar())
        ;
      if (_v == -1) a[_i] = -a[_i];
    }
  }
  int k;
  {
    char _c = getchar(), _v = 1;
    for (k = 0; _c < 48 || _c > 57; _c = getchar())
      if (_c == 45) _v = -1;
    for (; _c >= 48 && _c <= 57;
         k = (k << 1) + (k << 3) + _c - 48, _c = getchar())
      ;
    if (_v == -1) k = -k;
  }
  for (auto i = 0; i < k; ++i) {
    {
      char _c = getchar(), _v = 1;
      for (q[i].l = 0; _c < 48 || _c > 57; _c = getchar())
        if (_c == 45) _v = -1;
      for (; _c >= 48 && _c <= 57;
           q[i].l = (q[i].l << 1) + (q[i].l << 3) + _c - 48, _c = getchar())
        ;
      if (_v == -1) q[i].l = -q[i].l;
    }
    --q[i].l;
    {
      char _c = getchar(), _v = 1;
      for (q[i].r = 0; _c < 48 || _c > 57; _c = getchar())
        if (_c == 45) _v = -1;
      for (; _c >= 48 && _c <= 57;
           q[i].r = (q[i].r << 1) + (q[i].r << 3) + _c - 48, _c = getchar())
        ;
      if (_v == -1) q[i].r = -q[i].r;
    }
    --q[i].r;
    q[i].id = i;
  }
  std::sort(q, q + k);
  int top = 0;
  for (auto i = 0; i < k; ++i) {
    while (top <= q[i].r) {
      insert(a[top], top);
      ++top;
    }
    ans[q[i].id] = get_max(q[i].l);
  }
  for (auto i = 0; i < k; ++i) UPRT(ans[i]), putchar(10);
  return 0;
}
