#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
int p[maxn][21], pos[maxn][21];
void maintain(int now) {
  int x;
  scanf("%d", &x);
  int tmp = now;
  for (int i = 20; i >= 0; i--) {
    p[now][i] = p[now - 1][i];
    pos[now][i] = pos[now - 1][i];
  }
  for (int i = 20; i >= 0; i--) {
    if ((x >> i) & 1) {
      if (pos[now][i] == 0) {
        pos[now][i] = tmp;
        p[now][i] = x;
        break;
      }
      if (tmp > pos[now][i]) {
        swap(x, p[now][i]);
        swap(tmp, pos[now][i]);
      }
      x ^= p[now][i];
    }
  }
}
int main() {
  int n, m, l, r;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    maintain(i);
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &l, &r);
    int ans = 0;
    for (int i = 20; i >= 0; i--) {
      if (pos[r][i] >= l && (p[r][i] ^ ans) > ans) ans ^= p[r][i];
    }
    printf("%d\n", ans);
  }
}
