#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
void solve(){
int l,q; cin >> l >> q;
string s; cin >> s;
for(int _t = 0; _t < q; _t++){
string t; cin >> t;
int sum = 0;
reverse(t.begin(),t.end());
for(int i = 0; i < (1<<l); i++){
bool a = 1;
for(int j = 0; j < l; j++) if(t[j]!='?'){
if(t[j]-'0' != ((i>>j)&1)){a=0; break;}
}
if(a){
sum += s[i]-'0';
}
}
cout << sum << '\n';
}
}
signed main(){
cin.tie(0)->sync_with_stdio(false);
int t = 1;
while(t--){solve();}
}