#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
namespace fastio {
char rbuf[1 << 23], *p1 = rbuf, *p2 = rbuf, wbuf[1 << 23], *p3 = wbuf;
inline char getc() {
  return p1 == p2 &&
                 (p2 = (p1 = rbuf) + fread(rbuf, 1, 1 << 23, stdin), p1 == p2)
             ? -1
             : *p1++;
}
inline void putc(char x) { (*p3++ = x); }
template <typename T>
void read(T &x) {
  x = 0;
  char c = getchar();
  T neg = 0;
  while (!isdigit(c)) neg |= !(c ^ '-'), c = getchar();
  while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  if (neg) x = (~x) + 1;
}
template <typename T>
void recursive_print(T x) {
  if (!x) return;
  recursive_print(x / 10);
  putc(x % 10 ^ 48);
}
template <typename T>
void print(T x) {
  if (!x) putc('0');
  if (x < 0) putc('-'), x = ~x + 1;
  recursive_print(x);
}
void print_final() { fwrite(wbuf, 1, p3 - wbuf, stdout); }
}  // namespace fastio
const int MAXN = 5e5;
const int MAXB = 20;
int n, qu;
struct linear_base {
  int a[MAXB + 3], pos[MAXB + 5];
  linear_base() { memset(a, 0, sizeof(a)); }
  void init() { memset(a, 0, sizeof(a)); }
  void ins(int x, int p) {
    for (int i = MAXB; ~i; i--)
      if (x >> i & 1) {
        if (!a[i]) {
          a[i] = x;
          pos[i] = p;
          return;
        } else if (pos[i] < p)
          swap(a[i], x), swap(pos[i], p);
        x ^= a[i];
      }
  }
  int query(int l) {
    int ret = 0;
    for (int i = MAXB; ~i; i--)
      if (pos[i] >= l && (ret ^ a[i]) > ret) ret ^= a[i];
    return ret;
  }
} pre[MAXN + 5];
int main() {
  scanf("%d", &n);
  for (int i = 1, x; i <= n; i++)
    scanf("%d", &x), pre[i] = pre[i - 1], pre[i].ins(x, i);
  scanf("%d", &qu);
  while (qu--) {
    int l, r;
    scanf("%d%d", &l, &r);
    printf("%d\n", pre[r].query(l));
  }
  return 0;
}
