#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool uax(T &x, T y) {
  return x < y ? (x = y, true) : false;
}
template <typename T>
bool uin(T &x, T y) {
  return x > y ? (x = y, true) : false;
}
template <typename T>
void read(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
template <typename T>
void print(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (!x) {
    putchar('0');
    return;
  }
  if (x < 10)
    putchar(x + 48);
  else
    print(x / 10), putchar(x % 10 + 48);
}
template <typename T>
void print(T x, char gz) {
  print(x);
  putchar(gz);
}
constexpr int N = 500010;
constexpr int M = 500010;
constexpr int BN = 32;
struct LB {
  int a[BN], pos[BN];
  void insert(LB A, int id, int val) {
    *this = A;
    if (val == 0) return;
    for (int i = 31; i >= 0; --i) {
      if (!((val >> i) & 1)) continue;
      if (!a[i]) {
        a[i] = val;
        pos[i] = id;
      } else if (pos[i] < id) {
        swap(pos[i], id);
        swap(val, a[i]);
      }
      val ^= a[i];
    }
  }
  int query(int l) {
    int res = 0;
    for (int i = 31; i >= 0; --i) {
      if (pos[i] >= l) {
        uax(res, res ^ a[i]);
      }
    }
    return res;
  }
} a[N];
int n;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  read(n);
  for (int i = 1; i <= n; ++i) {
    int x;
    read(x);
    a[i].insert(a[i - 1], i, x);
  }
  int q;
  read(q);
  for (int i = 1; i <= q; ++i) {
    int l, r;
    read(l);
    read(r);
    print(a[r].query(l), '\n');
  }
  return 0;
}
