#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int a[maxn][25], pos[maxn][25];
int B[21];
int main() {
  B[0] = 1;
  for (int i = 1; i < 21; i++) {
    B[i] = B[i - 1] << 1;
  }
  int n, m, x;
  memset(a, -1, sizeof(a));
  memset(pos, -1, sizeof(pos));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    int ti = i;
    if (i != 0) {
      for (int j = 20; j >= 0; j--) {
        a[i][j] = a[i - 1][j];
        pos[i][j] = pos[i - 1][j];
      }
    }
    for (int j = 20; j >= 0; j--) {
      if (x & B[j]) {
        if (a[i][j] == -1) {
          a[i][j] = x;
          pos[i][j] = ti;
          break;
        } else if (pos[i][j] < ti) {
          swap(pos[i][j], ti);
          swap(a[i][j], x);
        }
        x ^= a[i][j];
      }
    }
  }
  scanf("%d", &m);
  while (m--) {
    int l, r, ret = 0;
    scanf("%d%d", &l, &r);
    l--;
    r--;
    for (int j = 20; j >= 0; j--)
      if (a[r][j] != -1) {
        if (pos[r][j] >= l) {
          ret = max(ret, ret ^ a[r][j]);
        }
      }
    printf("%d\n", ret);
  }
  return 0;
}
