/**
* بسم الله الرحمن الرحيم *
﴾ رَبِّ اشْرَحْ لِي صَدْرِي * وَيَسِّرْ لِي أَمْرِي * وَاحْلُلْ عُقْدَةً مِّن لِّسَانِي * يَفْقَهُوا قَوْلِي ﴿
*/
/// author : ASGA"
///
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using lll=__int128;
using ld=long double;
const ll inf=1e18;
char d[(1<<20)+10]{};
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
string s;int l,q;cin>>l>>q>>s;
int n=1<<l;
for(int i=0;i<n;i++)d[i]=(s[i]-'0');
int tot=accumulate(d,d+n,0);
while(q--){
cin>>s;reverse(s.begin(),s.end());
int a=0,b=0;
for(int i=0;i<l;i++){
if(s[i]=='1')b|=1<<i;
if(s[i]!='?')a|=1<<i;
}
int c=0;
for(int i=0;i<n;i++){
if((i&a)==b)c+=d[i];
}
cout<<c<<'\n';
}
return 0;
}