#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
int p[maxn][21], pos[maxn][21];
int main() {
  int N, Q, L, R, x;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= 20; j++)
      p[i][j] = p[i - 1][j], pos[i][j] = pos[i - 1][j];
    scanf("%d", &x);
    int ti = i;
    for (int j = 20; j >= 0; j--) {
      if (x & (1 << j)) {
        if (!p[i][j]) {
          p[i][j] = x;
          pos[i][j] = ti;
          break;
        }
        if (pos[i][j] < ti) swap(p[i][j], x), swap(pos[i][j], ti);
        x ^= p[i][j];
      }
    }
  }
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    scanf("%d%d", &L, &R);
    int res = 0;
    for (int j = 20; j >= 0; j--)
      if (pos[R][j] >= L && (res ^ p[R][j]) > res) res ^= p[R][j];
    printf("%d\n", res);
  }
  return 0;
}
