#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T lowbit(T x) {
  return x & (-x);
}
template <class T>
T gcd(T a, T b) {
  return b ? gcd(b, a % b) : a;
}
template <class T>
inline T Pow(T a, T b, T p) {
  T ret = 1;
  for (; b; b >>= 1, a = a * a % p)
    if (b & 1) (ret *= a) %= p;
  return ret;
}
template <class T>
inline void read(T &ret) {
  T x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  ret = x * f;
}
const int N = 500010, K = 20;
int n, m, a[N], ans[N], b[N][K];
pair<int, int> ask[N];
vector<int> pool[N];
void expand(int x, const int *prev, int *cur) {
  for (int i = (0); i <= (K - 1); i++) cur[i] = prev[i];
  int tmp = a[x];
  for (int i = (K - 1); i >= (0); i--)
    if ((tmp >> i) & 1) {
      if (cur[i])
        tmp ^= cur[i];
      else {
        cur[i] = tmp;
        break;
      }
    }
}
int calc(int x, int y) {
  int cur[K];
  for (int i = (0); i <= (K - 1); i++) cur[i] = b[x][i];
  for (int i = (0); i <= (K - 1); i++)
    if (b[y][i]) {
      int tmp = b[y][i];
      for (int j = (K - 1); j >= (0); j--)
        if ((tmp >> j) & 1) {
          if (cur[j])
            tmp ^= cur[j];
          else {
            cur[j] = tmp;
            break;
          }
        }
    }
  int ret = 0;
  for (int i = (K - 1); i >= (0); i--)
    if ((ret ^ cur[i]) > ret) ret ^= cur[i];
  return ret;
}
void solv(int l, int r) {
  if (l == r) {
    for (auto i = pool[l].begin(); i != pool[l].end(); i++)
      if (ask[*i].second == l) ans[*i] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  vector<int> stk;
  for (int i = (l); i <= (mid); i++)
    for (auto j = pool[i].begin(); j != pool[i].end(); j++)
      if (ask[*j].second > mid && ask[*j].second <= r) stk.push_back(*j);
  int tmp[K];
  fill(tmp, tmp + K, 0);
  for (int i = (mid); i >= (l); i--) expand(i, i == mid ? tmp : b[i + 1], b[i]);
  for (int i = (mid + 1); i <= (r); i++)
    expand(i, i == mid + 1 ? tmp : b[i - 1], b[i]);
  for (auto i = stk.begin(); i != stk.end(); i++)
    ans[*i] = calc(ask[*i].first, ask[*i].second);
  solv(l, mid);
  solv(mid + 1, r);
}
int main() {
  read(n);
  for (int i = (1); i <= (n); i++) read(a[i]);
  read(m);
  for (int i = (1); i <= (m); i++)
    read(ask[i].first), read(ask[i].second), pool[ask[i].first].push_back(i);
  solv(1, n);
  for (int i = (1); i <= (m); i++) printf("%d\n", ans[i]);
}
