#include <bits/stdc++.h>
using namespace std;
template <class U, class T>
void Max(U &first, T second) {
  if (first < second) first = second;
}
template <class U, class T>
void Min(U &first, T second) {
  if (first > second) first = second;
}
template <class T>
void add(int &a, T b) {
  a = (a + b) % 1000000007;
}
inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
inline long long gcd(long long a, long long b) {
  return b == 0 ? a : gcd(b, a % b);
}
int pow(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1LL * ans * a % 1000000007;
    a = 1LL * a * a % 1000000007;
    b >>= 1;
  }
  return ans;
}
int pow(int a, int b, int c) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = 1LL * ans * a % c;
    a = 1LL * a * a % c;
    b >>= 1;
  }
  return ans;
}
int a[500010], ans[500010];
vector<int> v[500010];
vector<pair<int, int> > q[500010];
void solve(int l, int r) {
  if (l == r) return;
  if (l + 1 == r) {
    for (int it = 0; it < q[l].size(); it++) {
      if (q[l][it].first == l) {
        ans[q[l][it].second] = a[l];
        swap(q[l][it], q[l].back());
        it--;
        q[l].pop_back();
      }
    }
    return;
  }
  int m = (l + r) >> 1;
  for (int i = 0; i < 20; i++) v[m][i] = 0;
  for (int i = m - 1; i >= l; i--) {
    int w = a[i];
    v[i] = v[i + 1];
    for (int j = 20 - 1; j >= 0; j--)
      if (w >> j & 1) {
        if (v[i][j])
          w ^= v[i][j];
        else {
          v[i][j] = w;
          break;
        }
      }
  }
  vector<int> w;
  for (int i = m; i < r; i++) {
    int first = a[i];
    for (int j = 20 - 1; j >= 0; j--)
      if (first >> j & 1) {
        if (v[i][j])
          first ^= v[i][j];
        else {
          v[i][j] = first;
          break;
        }
      }
    v[i + 1] = v[i];
    for (int it = 0; it < q[i].size(); it++)
      if (q[i][it].first < m) {
        int L = q[i][it].first, id = q[i][it].second;
        w = v[L];
        for (int j = 20 - 1; j >= 0; j--)
          if (v[i][j]) {
            first = v[i][j];
            for (int k = j + 1 - 1; k >= 0; k--)
              if (first >> k & 1) {
                if (w[k])
                  first ^= w[k];
                else {
                  w[k] = first;
                  break;
                }
              }
          }
        first = 0;
        for (int j = 20 - 1; j >= 0; j--) {
          int second = (first * 2 + 1) << j;
          for (int k = 20 - 1; k >= j; k--)
            if (second >> k & 1) {
              second ^= w[k];
            }
          second &= (((1 << 20 - j) - 1) << j);
          if (second == 0)
            first = first * 2 + 1;
          else
            first = first * 2;
        }
        ans[id] = first;
        swap(q[i][it], q[i].back());
        q[i].pop_back();
        it--;
      }
  }
  solve(l, m);
  solve(m, r);
}
int main() {
  int ca = 0, k, i, j, m = 0, K, n;
  double start = clock();
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int i = 0; i < n + 1; i++) v[i].resize(20);
  scanf("%d", &m);
  for (int i = 0; i < m; i++)
    scanf("%d%d", &j, &k), q[k - 1].push_back({j - 1, i});
  solve(0, n);
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  cerr << (1. * clock() - start) / CLOCKS_PER_SEC << "\n";
}
