#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int maxn = 1e2 + 5;
int a[500005];
int ans[25][500005];
int pos[25][500005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 23; j >= 0; j--) {
      ans[j][i] = ans[j][i - 1];
      pos[j][i] = pos[j][i - 1];
    }
    int tmp = i;
    int xx = a[i];
    for (int j = 23; j >= 0; j--) {
      if (xx & (1 << j)) {
        if (!ans[j][i]) {
          ans[j][i] = xx;
          pos[j][i] = tmp;
          break;
        }
        if (pos[j][i] < tmp) {
          swap(ans[j][i], xx);
          swap(tmp, pos[j][i]);
        }
        xx ^= ans[j][i];
      }
    }
  }
  int t;
  scanf("%d", &t);
  while (t--) {
    int l, r;
    scanf("%d%d", &l, &r);
    int an = 0;
    for (int i = 23; i >= 0; i--) {
      if (pos[i][r] >= l && ((an ^ ans[i][r]) > an)) {
        an ^= ans[i][r];
      }
    }
    printf("%d\n", an);
  }
  return 0;
}
