import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); int q = Integer.parseInt(sa[1]); sa = br.readLine().split(" "); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = Integer.parseInt(sa[i]); } char[] s = br.readLine().toCharArray(); sa = br.readLine().split(" "); int[] t = new int[q]; for (int i = 0; i < q; i++) { t[i] = Integer.parseInt(sa[i]); } br.close(); long[] dp0 = new long[31]; long[] dp1 = new long[31]; int now0 = 0; int now1 = Integer.MAX_VALUE; for (int i = 0; i < n; i++) { int next0 = 0; int next1 = 0; if (s[i] == '0') { next0 = now0 & a[i]; next1 = now1 & a[i]; } else { next0 = now0 | a[i]; next1 = now1 | a[i]; } for (int j = 0; j < 31; j++) { int c = 1 << j; if ((now0 & c) != (next0 & c)) { dp0[j] += c; } if ((now1 & c) != (next1 & c)) { dp1[j] += c; } } now0 = next0; now1 = next1; } PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < q; i++) { long ans = 0; for (int j = 0; j < 31; j++) { if ((t[i] >> j & 1) == 0) { ans += dp0[j]; } else { ans += dp1[j]; } } pw.println(ans); } pw.flush(); } }