N, Q = map(int, input().split()) A = list(map(int, input().split())) S = list(input()) S = list(map(int, S)) T = list(map(int, input().split())) M = 35 L = [[0] * 2 for i in range(M)] for i in range(M): for j in range(2): now = j for n in range(N): a = (A[n] >> i) & 1 if S[n]: nex = now | a else: nex = now & a L[i][j] += nex ^ now now = nex for t in T: ans = 0 for i in range(M): ans += (1 << i) * L[i][(t >> i) & 1] print(ans)