#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5;
int c[maxn];
int p[64], q[64];
int l[maxn];
int ans[maxn];
vector<int> g[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> c[i];
  int Q;
  cin >> Q;
  for (int i = 1; i <= Q; i++) {
    int r;
    cin >> l[i] >> r;
    g[r].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    int r = i, x = c[i];
    for (int j = 30; j >= 0; j--) {
      if (x >> j & 1) {
        if (!p[j]) {
          p[j] = x;
          q[j] = r;
          break;
        }
        if (q[j] < r) {
          swap(p[j], x);
          swap(q[j], r);
        }
        x ^= p[j];
      }
    }
    for (int k = 0; k < g[i].size(); k++) {
      int now = g[i][k];
      for (int j = 30; j >= 0; j--) {
        if (q[j] >= l[now]) ans[now] = max(ans[now], ans[now] ^ p[j]);
      }
    }
  }
  for (int i = 1; i <= Q; i++) cout << ans[i] << endl;
  return 0;
}
