#include <bits/stdc++.h>
using namespace std;
const int INF = 10000000;
const int maxn = 5e5 + 5;
int pos[maxn][60], xxj[maxn][60], c[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int k = 1; k <= n; k++) {
    for (int i = 50; i >= 0; i--) {
      pos[k][i] = pos[k - 1][i];
      xxj[k][i] = xxj[k - 1][i];
    }
    int tmp = k;
    for (int i = 50; i >= 0; i--) {
      if (c[k] & (1ll << i)) {
        if (xxj[k][i] && pos[k][i] < tmp) {
          swap(xxj[k][i], c[k]);
          swap(tmp, pos[k][i]);
        } else if (xxj[k][i] == 0) {
          pos[k][i] = tmp;
          xxj[k][i] = c[k];
          break;
        }
        c[k] ^= xxj[k][i];
      }
    }
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int l, r;
    scanf("%d%d", &l, &r);
    int ans = 0;
    for (int i = 50; i >= 0; i--) {
      if (pos[r][i] >= l && (ans ^ xxj[r][i]) > ans) {
        ans ^= xxj[r][i];
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
