n,q=map(int,input().split()) a=list(map(int,input().split())) s=input() t=list(map(int,input().split())) l=max(max(a),max(t)).bit_length() points=[[0]*2 for _ in range(l)] for i in range(l-1,-1,-1): k=2**i tmp1=0 tmp2=1 for j in range(n): if s[j]=='0': #bit on if a[j]&k: continue #bit off else: if tmp1==1: tmp1=0 points[i][0]+=k if tmp2==1: tmp2=0 points[i][1]+=k elif s[j]=='1': #bit on if a[j]&k: if tmp1==0: tmp1=1 points[i][0]+=k if tmp2==0: tmp2=1 points[i][1]+=k #bit off else: continue for val in t: tmp=0 for i in range(l-1,-1,-1): #bit on if val&(2**i): tmp+=points[i][1] #bit off else: tmp+=points[i][0] print(tmp)