N,Q = map(int,input().split()) A = list(map(int,input().split())) S = list(input()) T = list(map(int,input().split())) ZEROSUM = [0]*40 ONESUM = [0]*40 zero = [0]*40 one = [1]*40 for i in range(N): s = int(S[i]) a = A[i] ab = list(format(a, 'b').zfill(40))[::-1] for j in range(40): ab[j] = int(ab[j]) for j in range(40): if s==0: if zero[j]==1 and ab[j]==0: ZEROSUM[j]+=pow(2,j) if one[j]==1 and ab[j]==0: ONESUM[j]+=pow(2,j) zero[j] = zero[j]&ab[j] one[j] = one[j]&ab[j] else: if zero[j]==0 and ab[j]==1: ZEROSUM[j]+=pow(2,j) if one[j]==0 and ab[j]==1: ONESUM[j]+=pow(2,j) zero[j] = zero[j]|ab[j] one[j] = one[j]|ab[j] for t in T: B = list(format(t, 'b').zfill(40))[::-1] ans = 0 for i,b in enumerate(B): if B[i]=='0': ans+=ZEROSUM[i] else: ans+=ONESUM[i] print(ans)