n, q = map(int, input().split()) A = list(map(int, input().split())) S = input() T = list(map(int, input().split())) memo0 = [] memo1 = [] for i in range(32): vals = [(a >> i) & 1 for a in A] weight = 1 << i # i番目のbitが0のとき x = 0 score = 0 for s, v in zip(S, vals): if s == "0": xx = x & v else: xx = x | v if xx != x: score += weight x = xx memo0.append(score) # i番目のbitが0のとき x = 1 score = 0 for s, v in zip(S, vals): if s == "0": xx = x & v else: xx = x | v if xx != x: score += weight x = xx memo1.append(score) for t in T: ans = 0 for i in range(32): if (t >> i) & 1: ans += memo1[i] else: ans += memo0[i] print(ans)