#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int p[maxn][25];
int pos[maxn][25];
int l, r, q, x;
int main() {
  int n;
  scanf("%d", &n);
  memset(p, 0, sizeof p);
  memset(pos, 0, sizeof pos);
  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];
    cout << res << endl;
  }
  return 0;
}
