import java.util.*; import static java.lang.System.*; public class Main { public static void main(String[] args) { try (Scanner sc = new Scanner(in)) { int N = sc.nextInt(), Q = sc.nextInt(); int[] A = new int[N]; for (int i = 0;i < N;++ i) A[i] = sc.nextInt(); char[] S = sc.next().toCharArray(); long[] bit0 = new long[30], bit1 = new long[30]; for (int i = 0;i < 30;++ i) { int b0 = 0, b1 = 1; for (int j = 0;j < N;++ j) { if (S[j] == '0') { if ((A[j] >> i & 1) == 0 && b0 == 1) bit0[i] += 1 << i; if ((A[j] >> i & 1) == 0 && b1 == 1) bit1[i] += 1 << i; b0 &= A[j] >> i & 1; b1 &= A[j] >> i & 1; } else { if ((A[j] >> i & 1) != 0 && b0 == 0) bit0[i] += 1 << i; if ((A[j] >> i & 1) != 0 && b1 == 0) bit1[i] += 1 << i; b0 |= A[j] >> i & 1; b1 |= A[j] >> i & 1; } } } while(Q --> 0) { int t = sc.nextInt(); long ans = 0; for (int i = 0;i < 30;++ i) { if ((1 << i & t) == 0) ans += bit0[i]; else ans += bit1[i]; } out.println(ans); } } } }