#include <bits/stdc++.h>
using namespace std;
inline bool isvowel(char c) {
  c = tolower(c);
  if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u')
    return 1;
  return 0;
}
const double eps = 0.000001;
const long double pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const long long MOD = 1e18 + 9;
const long long INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 5e5 + 23;
const int M = 21;
const int pri = 997;
const int Magic = 2101;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int n, m, k;
int a[N];
int ans[N];
vector<pair<int, int> > g[N];
int was[M];
int pos[M];
void add(int id, int val) {
  for (int i = 20; i >= 0; i--)
    if (val & (1 << i)) {
      if (!was[i]) {
        was[i] = val, pos[i] = id;
        return;
      }
      if (pos[i] < id) swap(pos[i], id), swap(val, was[i]);
      val ^= was[i];
    }
}
int get(int l) {
  int res = 0;
  for (int i = 20; i >= 0; i--) {
    if (res & (1 << i) || pos[i] < l) continue;
    res ^= was[i];
  }
  return res;
}
int q;
void slow() {
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    int len = (r - l + 1);
    int ans = 0;
    for (int mask = 1; mask < (1 << len); mask++) {
      int cur = 0;
      for (int i = 0; i < len; i++)
        if (mask & (1 << i)) cur ^= a[i + l];
      ans = max(ans, cur);
    }
    cout << ans << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    g[r].push_back(make_pair(l, i));
  }
  for (int i = 1; i <= n; i++) {
    add(i, a[i]);
    for (auto e : g[i]) ans[e.second] = get(e.first);
  }
  for (int i = 1; i <= q; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}
