#include //#include using namespace std; //using namespace atcoder; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair P; int main() { int n, q; cin >> n >> q; vector a(n); rep(i,n) cin >> a[i]; string s; cin >> s; vector> dp(2, vector(31, 0)); for (int i = 0; i < 2; i++) { for (int j = 0; j < 31; j++) { int cur = i; for (int k = 0; k < n; k++) { int next = cur; if (s[k] == '1') next |= ((a[k] & (1 << j)) >> j); else next &= ((a[k] & (1 << j)) >> j); dp[i][j] += abs(cur - next) * (1 << j); cur = next; } } } while (q--) { int a; cin >> a; ll res = 0; for (int i = 0; i < 31; i++) { if (a & (1 << i)) res += dp[1][i]; else res += dp[0][i]; } cout << res << endl; } return 0; }