#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 3, M = 21;
int n, m, val[N], ans[N];
vector<pair<int, int> > a[N];
inline int in() {
  char c;
  int f = 1;
  while ((c = getchar()) < '0' || c > '9')
    if (c == '-') f = -1;
  int x = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
  return x * f;
}
struct Base {
  int bas[M], pos[M];
  inline void ins(int x, int t) {
    for (int i = 20; ~i; --i)
      if (x >> i & 1) {
        if (!bas[i]) {
          bas[i] = x, pos[i] = t;
          return;
        } else if (pos[i] < t)
          swap(bas[i], x), swap(pos[i], t);
        x ^= bas[i];
      }
  }
  inline int ask(int x, int t) {
    for (int i = 20; ~i; --i)
      if ((x ^ bas[i]) > x && pos[i] >= t) x ^= bas[i];
    return x;
  }
} A;
int main() {
  int x, y;
  n = in();
  for (int i = 1; i <= n; ++i) val[i] = in();
  m = in();
  for (int i = 1; i <= m; ++i)
    x = in(), y = in(), a[y].push_back(make_pair(x, i));
  for (int i = 1; i <= n; ++i) {
    A.ins(val[i], i);
    for (int j = 0; j < a[i].size(); ++j)
      ans[a[i][j].second] = A.ask(0, a[i][j].first);
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
  return 0;
}
