#include using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) int N, Q; int A[100000]; string S; int T[100000]; LL C[30][2] = {}; int main() { cin >> N >> Q; rep(i, N) cin >> A[i]; cin >> S; rep(i, Q) cin >> T[i]; rep(d, 30) rep(c, 2) { int m = 1 << d; int buf = c * m; rep(i, N) { int tmp = 0; if (S[i] == '0') tmp = buf & (m & A[i]); if (S[i] == '1') tmp = buf | (m & A[i]); C[d][c] += abs(tmp - buf); buf = tmp; } } rep(i, Q) { LL ans = 0; rep(d, 30) ans += C[d][(T[i] >> d) & 1]; cout << ans << endl; } return 0; }