local mfl, mce = math.floor, math.ceil local n, q = io.read("*n", "*n") local t = {} for i = 1, 30 do t[i] = {} end for i = 1, n do local a = io.read("*n") for j = 1, 30 do t[j][i] = a % 2 a = mfl(a / 2) end end io.read() local s = io.read() local tp = {} for i = 1, n do tp[i] = s:byte(i) == 48 end local score_0 = {} local score_1 = {} for i = 1, 30 do local s0, s1 = 0, 0 local c0, c1 = 0, 1 for j = 1, n do if tp[j] then -- AND if t[i][j] == 0 then if c0 == 1 then s0 = s0 + 1 end if c1 == 1 then s1 = s1 + 1 end c0, c1 = 0, 0 end else -- OR if t[i][j] == 1 then if c0 == 0 then s0 = s0 + 1 end if c1 == 0 then s1 = s1 + 1 end c0, c1 = 1, 1 end end end score_0[i], score_1[i] = s0, s1 end for iq = 1, q do local a = io.read("*n") local mul = 1 local ret = 0 for i = 1, 30 do if a % 2 == 1 then ret = ret + score_1[i] * mul else ret = ret + score_0[i] * mul end a = mfl(a / 2) mul = mul * 2 end ret = tostring(ret * 1LL):gsub("LL", "") print(ret) end