#include <bits/stdc++.h>
using namespace std;
const double pai = acos(-1.0);
const double E = 2.718281828459;
const long long mod = 998244353;
const double esp = 1e-6;
const int INF = 0x3f3f3f3f;
const int maxn = 5e5 + 5;
int n, p[maxn][22], s[maxn][22];
void Insert(int x, int k, int r) {
  for (int i = 20; i >= 0; i--) {
    if (x >> i & 1) {
      if (!p[k][i]) {
        p[k][i] = x;
        s[k][i] = r;
        return;
      }
      if (s[k][i] < r) {
        swap(p[k][i], x);
        swap(s[k][i], r);
      }
      x ^= p[k][i];
    }
  }
}
int query(int l, int r) {
  int ans = 0;
  for (int i = 20; i >= 0; i--) {
    if (s[r][i] >= l) ans = max(ans, ans ^ p[r][i]);
  }
  return ans;
}
int main() {
  int x, q, l, r;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    for (int j = 0; j <= 19; j++) {
      p[i][j] = p[i - 1][j];
      s[i][j] = s[i - 1][j];
    }
    Insert(x, i, i);
  }
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &l, &r);
    printf("%d\n", query(l, r));
  }
  return 0;
}
