#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const int N = 5e5 + 10;
const double eps = 1e-14;
const double PI = acos(-1.0);
bool debug = false;
int v[N];
int ans[N];
struct Node {
  int l, r, id;
  bool operator<(const Node &it) const {
    if (l != it.l) return l > it.l;
    return r < it.r;
  }
} node[N];
vector<pair<int, int> > vc[2];
bool cmp1(pair<int, int> &a, pair<int, int> &b) { return a.second < b.second; }
bool cmp2(pair<int, int> &a, pair<int, int> &b) { return a.first > b.first; }
void solve() {
  int n, q, l, r;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &v[i]);
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i)
    scanf("%d %d", &node[i].l, &node[i].r), node[i].id = i;
  sort(node + 1, node + q + 1);
  int now = 0, pre = 1;
  for (int i = n, j = 1; i >= 1; --i) {
    swap(now, pre);
    vc[now].clear();
    vc[now].push_back({v[i], i});
    for (auto it : vc[pre]) {
      int gg = v[it.second];
      for (auto iit : vc[now]) gg = min(iit.first ^ gg, gg);
      if (gg) {
        vc[now].push_back({gg, it.second});
      }
    }
    sort(vc[now].begin(), vc[now].end(), cmp1);
    int id = 0, mmx = 0;
    while (j <= q && node[j].l == i) {
      while (id < vc[now].size() && vc[now][id].second <= node[j].r)
        mmx = max(mmx, mmx ^ vc[now][id].first), id++;
      ans[node[j].id] = mmx;
      ++j;
    }
  }
  for (int i = 1; i <= q; ++i) printf("%d\n", ans[i]);
}
int main() {
  solve();
  return 0;
}
