#include #include using namespace std; typedef long long LL; int main(){ ios::sync_with_stdio(false); cin.tie(0); const LL mask = (1LL << 60) - 1; int n; cin >> n; vector as(n); for(LL &a : as){ cin >> a; } LL rem = mask; vector v; bool free = false; for(int i = n - 1; i >= 0; --i){ LL b = rem & as[i]; if(b != 0){ v.push_back(b); rem ^= b; free = false; } else{ free = true; } } int q; cin >> q; for(int z = 0; z < q; ++z){ LL b; cin >> b; int ans = 0; for(LL x : v){ LL y = b & x; if(y != 0 && y != x){ ans = -1; break; } if((y == x) != (ans % 2 == 0)){ ++ans; } } if(ans != -1 && rem != 0){ LL y = b & rem; if(y != 0 && y != rem){ ans = -1; } else if((y == 0) != (ans % 2 == 0)){ if(free){ ++ans; } else{ ans = -1; } } } cout << ans << '\n'; } }