#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 10;
const int mod7 = 1e9 + 7;
const int mod = 1e9 + 7;
void read(int &a) {
  a = 0;
  int d = 1;
  char ch;
  while (ch = getchar(), ch > '9' || ch < '0')
    if (ch == '-') d = -1;
  a = ch ^ 48;
  while (ch = getchar(), ch >= '0' && ch <= '9')
    a = (a << 3) + (a << 1) + (ch ^ 48);
  a *= d;
}
int b[N][35], p[N][35];
void ins(int x, int v) {
  for (register int i = 0; i <= 30; i++) {
    p[x][i] = p[x - 1][i];
    b[x][i] = b[x - 1][i];
  }
  int now = x;
  for (register int i = 30; i >= 0; i--) {
    if (v & (1 << i)) {
      if (!b[x][i]) {
        b[x][i] = v;
        p[x][i] = now;
        return;
      }
      if (p[x][i] < now) {
        swap(b[x][i], v);
        swap(p[x][i], now);
      }
      v ^= b[x][i];
    }
  }
}
int query(int l, int r) {
  int ans = 0;
  for (register int i = 30; i >= 0; i--)
    if (p[r][i] >= l && (b[r][i] ^ ans) > ans) ans ^= b[r][i];
  return ans;
}
int main() {
  int n;
  read(n);
  for (register int i = 1, x; i <= n; i++) {
    read(x);
    ins(i, x);
  }
  int T;
  read(T);
  while (T--) {
    int l, r;
    read(l), read(r);
    printf("%d\n", query(l, r));
  }
  return 0;
}
