#include <bits/stdc++.h>
using namespace std;
class Solution {
  struct Query {
    int ql, id;
    Query(int ql, int id) : ql(ql), id(id) {}
  };
  vector<vector<Query>> rightBound;
  vector<int> lastHighBitPos, lastHighBitNum;
  int n, m;
  vector<int> ans, c;

 public:
  void run(istream &in, ostream &out) {
    in >> n;
    c.resize(n);
    for (int i = 0; i < n; ++i) in >> c[i];
    in >> m;
    rightBound.resize(n + 1);
    lastHighBitPos.assign(22, -1);
    lastHighBitNum.assign(22, -1);
    ans.resize(m);
    for (int i = 0; i < m; ++i) {
      int ql, r;
      in >> ql >> r;
      rightBound[r].emplace_back(ql - 1, i);
    }
    for (int i = 1; i <= n; ++i) {
      int a = c[i - 1], pos = i - 1;
      for (int j = 21; j >= 0; --j) {
        if (a >> j & 1) {
          if (lastHighBitPos[j] == -1) {
            lastHighBitPos[j] = pos;
            lastHighBitNum[j] = a;
            break;
          }
          if (lastHighBitPos[j] < pos) {
            swap(lastHighBitNum[j], a);
            swap(lastHighBitPos[j], pos);
          }
          a ^= lastHighBitNum[j];
        }
      }
      for (Query q : rightBound[i]) {
        int cur = 0;
        for (int j = 21; j >= 0; --j) {
          if (lastHighBitPos[j] >= q.ql)
            cur = max(cur, cur xor lastHighBitNum[j]);
        }
        ans[q.id] = cur;
      }
    }
    for (int i = 0; i < m; ++i) out << ans[i] << '\n';
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  Solution().run(cin, cout);
}
