#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve (){
int n;
cin>>n;
int k;
cin>>k;
k++;
string s;
cin>>s;
int index=0;
for (int i=0;i<s.length();i++){
	if(s[i]=='1'){
		index=i;break;
	}
}
int count=0;
for (int i=index+k;i<s.length();i=i+k){
	if (s[i]=='0'){
		bool flag1=true;
		bool flag2=true;
		for (int j=1;j<k&&(i+j)<s.length();j++){
			if (s[i+j]=='1'){
				flag1=false;
				break;
			}
		}
		for (int j=1;j<k&&(i-j)>=0;j++){
			if(s[i-j]=='1'){
				flag2=false;
				break;
			}
		}
		if(flag1&&flag2)count++;
	}
}
for (int i=index-k;i>=0;i-=k){
	if(s[i]=='0'){
		bool flag1=true;
		bool flag2=true;
		for (int j=1;j<k&&(i-j)>=0;j++){
			if(s[i-j]=='1'){
				flag1=false;
				break;
			}
		}
		for (int j=1;j<k&&(i+j)<s.length();j++){
			if (s[i+j]=='1'){
				flag2=false;
				break;
			}
		}
		if(flag1&&flag2)count++;
	}
}
cout<<count<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve ();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve (){
int n;
cin>>n;
int k;
cin>>k;
k++;
string s;
cin>>s;
int l=s.length();
queue<int> q;
int count=0;
for (int i=0;i<l;i++){
	if (s[i]=='1')q.push(i);
}
while (!q.empty()){
	int i =q.front();
	q.pop();
	bool flag1=true;
	bool flag2=true;
	for (int j=1;j<=k&&(i+j)<l;j++){
		if (s[i+j]=='1')flag1=false;
	}
	for (int j=1;j<=k&&(i-j)>=0;j++){
		if(s[i-j]=='1')flag2=false;
	}
	if ((i+k<n)&&flag1==true){
		s[i+k]='1';
		q.push(i+k);
		count++;
	}
	if (i-k>=0&&flag2==true){
		s[i-k]='1';
		q.push(i-k);
		count++;
	}

}
cout<<count<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve ();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve (){
int n;
cin>>n;
int k;
cin>>k;
k++;
string s;
cin>>s;
int index=0;
for (int i=0;i<s.length();i++){
	if(s[i]=='1'){
		index=i;break;
	}
}
int count=0;
for (int i=index;i<s.length();i=i+k){
	if (s[i]=='0'){
		bool flag1=true;
		bool flag2=true;
		for (int j=1;j<k&&(i+j)<s.length();j++){
			if (s[i+j]=='1'){
				flag1=false;
				break;
			}
		}
		for (int j=1;j<k&&(i-j)>=0;j++){
			if(s[i-j]=='1'){
				flag2=false;
				break;
			}
		}
		if(flag1&&flag2){
			s[i]=1;
			count++;
		}
	}
}
for (int i=index-k;i>=0;i-=k){
	if(s[i]=='0'){
		bool flag1=true;
		bool flag2=true;
		for (int j=1;j<k&&(i-j)>=0;j++){
			if(s[i-j]=='1'){
				flag1=false;
				break;
			}
		}
		for (int j=1;j<k&&(i+j)<s.length();j++){
			if (s[i+j]=='1'){
				flag2=false;
				break;
			}
		}
		if(flag1&&flag2){
			s[i]=1;
			count++
		}
	}
}
cout<<count<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve ();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve (){
int n;
cin>>n;
int k;
cin>>k;
k++;
string s;
cin>>s;
int index=0;
for (int i=0;i<s.length();i++){
	if(s[i]=='1'){
		index=i;break;
	}
}
int count=0;
for (int i=index;i<s.length();i=i+k){
	if (s[i]=='0'){
		bool flag1=true;
		bool flag2=true;
		for (int j=1;j<k&&(i+j)<s.length();j++){
			if (s[i+j]=='1'){
				flag1=false;
				break;
			}
		}
		for (int j=1;j<k&&(i-j)>=0;j++){
			if(s[i-j]=='1'){
				flag2=false;
				break;
			}
		}
		if(flag1&&flag2){
			s[i]=1;
			count++;
		}
	}
}
for (int i=index-k;i>=0;i-=k){
	if(s[i]=='0'){
		bool flag1=true;
		bool flag2=true;
		for (int j=1;j<k&&(i-j)>=0;j++){
			if(s[i-j]=='1'){
				flag1=false;
				break;
			}
		}
		for (int j=1;j<k&&(i+j)<s.length();j++){
			if (s[i+j]=='1'){
				flag2=false;
				break;
			}
		}
		if(flag1&&flag2){
			s[i]=1;
			count++;
		}
	}
}
cout<<count<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve ();
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void solve (){
int n;
cin>>n;
int k;
cin>>k;
k++;
string s;
cin>>s;
int index=0;
for (int i=0;i<s.length();i++){
	if(s[i]=='1'){
		index=i;break;
	}
}
int count=0;
for (int i=index;i<s.length();i=i+k){
	if (s[i]=='0')count++;
}
for (int i=index;i>=0;i-=k){
	if(s[i]=='0')count++;
}
cout<<count<<endl;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		solve ();
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 60005
const ll inf=1e9+7;
#define pb push_back
#define PI 3.14159265
#define watch(x) cerr << (#x) << " is " << (x) << endl;
void solve();
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<fixed;
	cout<<setprecision(10);
	int t=1;
	cin>>t;
	while(t--)
	solve();
	return 0;
}
bool pal(string s)
{
	string t=s;
	reverse(s.begin(),s.end());
	return (t==s);
}
ll countdig(ll x)
{
	ll c=0;
	if(x==0)
	return 1;

	while(x!=0)
	{
		c++;
		x/=10;
	}
	return c;
}
struct topic
{
	ll a;
	ll b;
};
bool comp(ll a,ll b)
{
	return (a>b);
}
void solve()
{
	ll n,k,i;
	cin>>n>>k;
	string arr;
	cin>>arr;

	ll left,right;
	for(i=0;i<n;i++)
	{
		if(arr[i]=='1')
		break;
	}
	left=i;
	for(i=n-1;i>=0;i--)
	{
		if(arr[i]=='1')
		break;
	}
	right=i;
	if(left==n)
	cout<<max(1LL,n/(k+1));
	else
	{
		ll ans=left/(k+1)+(n-1-right)/(k+1);
		ll p=0;
		for(i=left+k+1;i<=right-k-1;i++)
		{
			if(arr[i]=='0')
			p++;
			else
			{
				ans+=max(1LL,p/(k+1));
				p=0;
			}
		}
		ans+=max(1LL,p/(k+1));
		cout<<ans;

	}
	cout<<endl;
	//cout<<left<<" "<<right-left-1<<" "<<n-1-right<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 60005
const ll inf=1e9+7;
#define pb push_back
#define PI 3.14159265
#define watch(x) cerr << (#x) << " is " << (x) << endl;
void solve();
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<fixed;
	cout<<setprecision(10);
	int t=1;
	cin>>t;
	while(t--)
	solve();
	return 0;
}
bool pal(string s)
{
	string t=s;
	reverse(s.begin(),s.end());
	return (t==s);
}
ll countdig(ll x)
{
	ll c=0;
	if(x==0)
	return 1;

	while(x!=0)
	{
		c++;
		x/=10;
	}
	return c;
}
struct topic
{
	ll a;
	ll b;
};
bool comp(ll a,ll b)
{
	return (a>b);
}
void solve()
{
	ll n,k,i;
	cin>>n>>k;
	string arr;
	cin>>arr;

	ll left,right;
	for(i=0;i<n;i++)
	{
		if(arr[i]=='1')
		break;
	}
	left=i;
	for(i=n-1;i>=0;i--)
	{
		if(arr[i]=='1')
		break;
	}
	right=i;
	if(left==n)
	cout<<max(1LL,n/(k+1));
	else
	{
		ll ans=left/(k+1)+(n-1-right)/(k+1);
		ll p=0;
		for(i=left+k+1;i<=right;i++)
		{
			if(arr[i]=='0')
			p++;
			else
			{
				ans+=p/(k+1);
				p=0;
			}
		}
		if(p!=0)
		ans+=p/(k+1);
		cout<<ans;

	}
	cout<<endl;
	//cout<<left<<" "<<right-left-1<<" "<<n-1-right<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 60005
const ll inf=1e9+7;
#define pb push_back
#define PI 3.14159265
#define watch(x) cerr << (#x) << " is " << (x) << endl;
void solve();
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<fixed;
	cout<<setprecision(10);
	int t=1;
	cin>>t;
	while(t--)
	solve();
	return 0;
}
bool pal(string s)
{
	string t=s;
	reverse(s.begin(),s.end());
	return (t==s);
}
ll countdig(ll x)
{
	ll c=0;
	if(x==0)
	return 1;

	while(x!=0)
	{
		c++;
		x/=10;
	}
	return c;
}
struct topic
{
	ll a;
	ll b;
};
bool comp(ll a,ll b)
{
	return (a>b);
}
void solve()
{
	ll n,k,i;
	cin>>n>>k;
	string arr;
	cin>>arr;

	ll left,right;
	for(i=0;i<n;i++)
	{
		if(arr[i]=='1')
		break;
	}
	left=i;
	for(i=n-1;i>=0;i--)
	{
		if(arr[i]=='1')
		break;
	}
	right=i;
	if(left==n)
	cout<<max(1LL,(ll)ceil(1.0*n/(k+1)));
	else
	{
		ll ans=left/(k+1)+(n-1-right)/(k+1);
		ll p=0;
		for(i=left+k+1;i<=right;i++)
		{
			if(arr[i]=='0')
			p++;
			else
			{
				ans+=p/(k+1);
				p=0;
			}
		}
		if(p!=0)
		ans+=p/(k+1);
		cout<<ans;

	}
	cout<<endl;
	//cout<<left<<" "<<right-left-1<<" "<<n-1-right<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 1e9+7
#define maxn 1e6
#define ll long long int
void solve();
int main()
{
	int t;
	t=1;
	cin>>t;
	while(t--)
	solve();
	return 0;
}
void solve()
{
	ll n,k,i;
	cin>>n>>k;
	string s;
	cin>>s;
	ll p=0,extra=0;
	ll first=0,last=0;
	for(i=0;i<n;i++)
	{
		if(s[i]=='1')
		break;
	}
	first=i;
	for(i=n-1;i>=0;i--)
	{
		if(s[i]=='1')
		break;
	}
	last=i;
	if(first==last)
	{
		extra+=((first/(k+1))+(n-1-last)/(k+1));
	}
	else if(first==n&&last==-1)
	{
		extra+=max(1LL,n/(k+1));
	}
	else //normal
	{
		extra+=((first/(k+1))+(n-1-last)/(k+1));
		p=0;
		for(i=first;i<n;i++)
		{
			if(s[i]=='1')
			{
				extra+=(p/(2*k+1));
				p=0;
			}
		else
		p++;
		}
	}
	cout<<extra<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 1e9+7
#define maxn 1e6
#define ll long long int
void solve();
int main()
{
	int t;
	t=1;
	cin>>t;
	while(t--)
	solve();
	return 0;
}
void solve()
{
	ll n,k,i;
	cin>>n>>k;
	string s;
	cin>>s;
	ll p=0,extra=0;
	ll first=0,last=0;
	for(i=0;i<n;i++)
	{
		if(s[i]=='1')
		break;
	}
	first=i;
	for(i=n-1;i>=0;i--)
	{
		if(s[i]=='1')
		break;
	}
	last=i;
	//cout<<first<<" "<<last<<endl;
	if(first==last)
	{

		extra+=((first/(k+1))+(n-1-last)/(k+1));
	}
	else if(first==n&&last==-1)
	{
		extra+=max(1LL,(ll)ceil(1.0*n/(k+1)));
	}
	else //normal
	{
		extra+=((first/(k+1))+(n-1-last)/(k+1));
		p=0;
		for(i=first;i<=last;i++)
		{
			if(s[i]=='1')
			{
				ll del=(p/(2*k+1));
				extra+=del;
				p-=(2*k+1)*del;
				if(p>k&&del)
					extra++;
				p=0;
			}
			else
			p++;
		}
	}
	cout<<extra<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 1e9+7
#define maxn 1e6
#define ll long long int
void solve();
int main()
{
	int t;
	t=1;
	cin>>t;
	while(t--)
	solve();
	return 0;
}
void solve()
{
	ll n,k,i;
	cin>>n>>k;
	string s;
	cin>>s;
	ll p=0,extra=0;
	ll first=0,last=0;
	for(i=0;i<n;i++)
	{
		if(s[i]=='1')
		break;
	}
	first=i;
	for(i=n-1;i>=0;i--)
	{
		if(s[i]=='1')
		break;
	}
	last=i;
	//cout<<first<<" "<<last<<endl;
	if(first==last)
	{
		extra+=((first/(k+1))+(n-1-last)/(k+1));
	}
	else if(first==n&&last==-1)
	{
		extra+=max(1LL,(ll)ceil(1.0*n/(k+1)));
	}
	else //normal
	{
		extra+=((first/(k+1))+(n-1-last)/(k+1));
		p=0;
		for(i=first;i<=last;i++)
		{
			if(s[i]=='1')
			{
				ll del=(p/(2*k+1));
				extra+=del;
				p-=(2*k+1)*del;
				if(p>k)
				extra++;
				p=0;
			}
		else
		p++;
		}
	}
	cout<<extra<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 60005
const ll inf=1e9+7;
#define pb push_back
#define PI 3.14159265
#define watch(x) cerr << (#x) << " is " << (x) << endl;
void solve();
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<fixed;
	cout<<setprecision(10);
	int t=1;
	cin>>t;
	while(t--)
	solve();
	return 0;
}
bool pal(string s)
{
	string t=s;
	reverse(s.begin(),s.end());
	return (t==s);
}
ll countdig(ll x)
{
	ll c=0;
	if(x==0)
	return 1;

	while(x!=0)
	{
		c++;
		x/=10;
	}
	return c;
}
struct topic
{
	ll a;
	ll b;
};
bool comp(ll a,ll b)
{
	return (a>b);
}
void solve()
{
	    		ll n,k;
    		cin>>n>>k;
    		vector<int> vec;
    		vec.pb(-k);
    		string s;
    		cin>>s;
    		for(int i=0;i<n;i++){
    			if(s[i]=='1')vec.pb(i+1);
    		}
    		vec.pb(n+k+1);
    		ll ans=0;
    		for(int i=0;i<(int)vec.size()-1;i++){
    			int ind=vec[i]+k+1;
    			// cout<<"ind: "<<ind<<"\n";
    			while(ind+k<vec[i+1]){
    				ans++;
    				ind+=k+1;
    			}
    		}
    		cout<<ans<<"\n";
   }


#include<bits/stdc++.h>
using namespace std;
#define inf 1e9+7
#define maxn 1e6
#define ll long long int
void solve();
int main()
{
	int t;
	t=1;
	cin>>t;
	while(t--)
	solve();
	return 0;
}
void solve()
{
	ll n,k,i;
	cin>>n>>k;
	string s;
	cin>>s;
	ll p=0,extra=0;
	ll first=0,last=0;
	for(i=0;i<n;i++)
	{
		if(s[i]=='1')
		break;
	}
	first=i;
	for(i=n-1;i>=0;i--)
	{
		if(s[i]=='1')
		break;
	}
	last=i;
	//cout<<first<<" "<<last<<endl;
	if(first==last)
	{

		extra+=((first/(k+1))+(n-1-last)/(k+1));
	}
	else if(first==n&&last==-1)
	{
		extra+=max(1LL,(ll)ceil(1.0*n/(k+1)));
	}
	else //normal
	{
		extra+=((first/(k+1))+(n-1-last)/(k+1));
		p=0;
		for(i=first;i<=last;i++)
		{
			if(s[i]=='1')
			{
				ll del=(p/(2*k+1));
				extra+=del;
				p-=(2*k+1)*del;
				while(p>k&&del!=0)
				{
					extra++;
					p-=(2*k+1);
				}
				p=0;
			}
		else
		p++;
		}
	}
	cout<<extra<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 1e9+7
#define maxn 1e6
#define ll long long int
void solve();
int main()
{
	int t;
	t=1;
	cin>>t;
	while(t--)
	solve();
	return 0;
}
void solve()
{
	ll n,k,i;
	cin>>n>>k;
	string s;
	cin>>s;
	ll p=0,extra=0;
	ll first=0,last=0;
	for(i=0;i<n;i++)
	{
		if(s[i]=='1')
		break;
	}
	first=i;
	for(i=n-1;i>=0;i--)
	{
		if(s[i]=='1')
		break;
	}
	last=i;
	//cout<<first<<" "<<last<<endl;
	if(first==last)
	{
		extra+=((first/(k+1))+(n-1-last)/(k+1));
	}
	else if(first==n&&last==-1)
	{
		extra+=max(1LL,(ll)ceil(1.0*n/(k+1)));
	}
	else //normal
	{
		extra+=((first/(k+1))+(n-1-last)/(k+1));
		p=0;
		for(i=first;i<=last;i++)
		{
			if(s[i]=='1')
			{
				extra+=(p/(2*k+1));
				p=0;
			}
		else
		p++;
		}
	}
	cout<<extra<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 1e9+7
#define maxn 1e6
#define ll long long int
void solve();
int main()
{
	int t;
	t=1;
	cin>>t;
	while(t--)
	solve();
	return 0;
}
void solve()
{
	ll n,k,i;
	cin>>n>>k;
	string s;
	cin>>s;
	ll p=0,extra=0;
	ll first=0,last=0;
	for(i=0;i<n;i++)
	{
		if(s[i]=='1')
		break;
	}
	first=i;
	for(i=n-1;i>=0;i--)
	{
		if(s[i]=='1')
		break;
	}
	last=i;
	//cout<<first<<" "<<last<<endl;
	if(first==last)
	{
		extra+=((first/(k+1))+(n-1-last)/(k+1));
	}
	else if(first==n&&last==-1)
	{
		extra+=max(1LL,n/(k+1));
	}
	else //normal
	{
		extra+=((first/(k+1))+(n-1-last)/(k+1));
		p=0;
		for(i=first;i<=last;i++)
		{
			if(s[i]=='1')
			{
				extra+=(p/(2*k+1));
				p=0;
			}
		else
		p++;
		}
	}
	cout<<extra<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 60005
const ll inf=1e9+7;
#define pb push_back
#define PI 3.14159265
#define watch(x) cerr << (#x) << " is " << (x) << endl;
void solve();
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<fixed;
	cout<<setprecision(10);
	int t=1;
	cin>>t;
	while(t--)
	solve();
	return 0;
}
bool pal(string s)
{
	string t=s;
	reverse(s.begin(),s.end());
	return (t==s);
}
ll countdig(ll x)
{
	ll c=0;
	if(x==0)
	return 1;

	while(x!=0)
	{
		c++;
		x/=10;
	}
	return c;
}
struct topic
{
	ll a;
	ll b;
};
bool comp(ll a,ll b)
{
	return (a>b);
}
void solve()
{
	ll n,k,i;
	cin>>n>>k;
	string arr;
	cin>>arr;

	ll left,right;
	for(i=0;i<n;i++)
	{
		if(arr[i]=='1')
		break;
	}
	left=i;
	for(i=n-1;i>=0;i--)
	{
		if(arr[i]=='1')
		break;
	}
	right=i;
	if(left==n)
	cout<<max(1LL,n/(k+1));
	else
	{
		ll ans=left/(k+1)+(n-1-right)/(k+1);
		ll p=0;
		for(i=left+k+1;i<=right-k-1;i++)
		{
			if(arr[i]=='0')
			p++;
			else
			{
				ans+=max(1LL,p/(k+1));
				p=0;
			}
		}
		if(p!=0)
		ans+=max(1LL,p/(k+1));
		cout<<ans;

	}
	cout<<endl;
	//cout<<left<<" "<<right-left-1<<" "<<n-1-right<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define inf 1e9+7
#define maxn 1e6
#define ll long long int
void solve();
int main()
{
	int t;
	t=1;
	cin>>t;
	while(t--)
	solve();
	return 0;
}
void solve()
{
	ll n,k,i;
	cin>>n>>k;
	string s;
	cin>>s;
	ll p=0,extra=0;
	ll first=0,last=0;
	for(i=0;i<n;i++)
	{
		if(s[i]=='1')
		break;
	}
	first=i;
	for(i=n-1;i>=0;i--)
	{
		if(s[i]=='1')
		break;
	}
	last=i;
	//cout<<first<<" "<<last<<endl;
	if(first==last)
	{

		extra+=((first/(k+1))+(n-1-last)/(k+1));
	}
	else if(first==n&&last==-1)
	{
		extra+=max(1LL,(ll)ceil(1.0*n/(k+1)));
	}
	else //normal
	{
		extra+=((first/(k+1))+(n-1-last)/(k+1));
		p=0;
		for(i=first;i<=last;i++)
		{
			if(s[i]=='1')
			{
				ll del=(p/(2*k+1));
				extra+=del;
				p-=(2*k+1)*del;
				while(p>k)
				{
					extra++;
					p-=(2*k+1);
				}
				p=0;
			}
		else
		p++;
		}
	}
	cout<<extra<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define maxn 60005
const ll inf=1e9+7;
#define pb push_back
#define PI 3.14159265
#define watch(x) cerr << (#x) << " is " << (x) << endl;
void solve();
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<fixed;
	cout<<setprecision(10);
	int t=1;
	cin>>t;
	while(t--)
	solve();
	return 0;
}
bool pal(string s)
{
	string t=s;
	reverse(s.begin(),s.end());
	return (t==s);
}
ll countdig(ll x)
{
	ll c=0;
	if(x==0)
	return 1;

	while(x!=0)
	{
		c++;
		x/=10;
	}
	return c;
}
struct topic
{
	ll a;
	ll b;
};
bool comp(ll a,ll b)
{
	return (a>b);
}
void solve()
{
	ll n,k,i;
	cin>>n>>k;
	string arr;
	cin>>arr;

	ll left,right;
	for(i=0;i<n;i++)
	{
		if(arr[i]=='1')
		break;
	}
	left=i;
	for(i=n-1;i>=0;i--)
	{
		if(arr[i]=='1')
		break;
	}
	right=i;
	if(left==n)
	cout<<max(1LL,n/(k+1));
	else
	{
		ll ans=left/(k+1)+(n-1-right)/(k+1);
		ll p=0;
		for(i=left+k+1;i<=right-k-1;i++)
		{
			if(arr[i]=='0')
			p++;
			else
			{
				ans+=max(1LL,p/(k+1));
				p=0;
			}
		}
		ans+=p/(k+1);
		cout<<ans;

	}
	cout<<endl;
	//cout<<left<<" "<<right-left-1<<" "<<n-1-right<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll fast(ll x,ll n,ll mod){ll ans=1;while(n>0){if(n%2==1){ans = (ans* x)%mod;}x=x*x;x=x%mod;n=n/2;}return ans%mod;}
ll modi(ll a,ll mod){return fast(a,mod -2,mod);}
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	    ll n ,a[100005],b=0,c=0,ans=0,x,k;
	    string s;
	    vector<ll>v;
	    cin>>n>>k;
	    cin>>s;
	    v.pb(-k);
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1')
	        v.pb(i+1);
	    }
	    v.pb(n+k + 1);
	    for(int i=0;i<v.size()-1;i++)
	    {
	       // cout<<v[i]<<' '<<v[i+1]<<' ';
	        x=v[i+1]-v[i]-1;
	       // cout<<x<<endl;
	       if(x%2*k == 1)
	        ans+=x/(2*k);
	        else
	        ans+=x/(2*k + 1);
	    }
	   // if(c==0 && ans==0)
	   // ans=1;
	    cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll fast(ll x,ll n,ll mod){ll ans=1;while(n>0){if(n%2==1){ans = (ans* x)%mod;}x=x*x;x=x%mod;n=n/2;}return ans%mod;}
ll modi(ll a,ll mod){return fast(a,mod -2,mod);}
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	    ll n ,a[100005],b=0,c=0,ans=0,x,k;
	    string s;
	    vector<ll>v;
	    cin>>n>>k;
	    cin>>s;
	    v.pb(0);
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1' && b==0)
	        {
	            if(i>k)
	            {
	                s[0]='1';
	                ans++;
	            }
	            break;
	        }
	    }

	    for(int i=0;i<n;i++)
	    {
	        if(s[n-i-1]=='1' &&c==0)
	        {
	            if(i>k)
	            {
	               // cout<<'a';
	                s[n-1]='1';
	                ans++;
	            }
	            break;
	        }
	    }
	   // cout<<s<<endl;
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1' && b==0)
	        {
	            b=1;
	            break;
	        }
	    }
	    if(b==0)
	    {
	        s[0]='1';
	        ans++;
	        if(n-1>k)
	        {
	            s[n-1]='1';
	            ans++;
	        }
	    }
	   // cout<<ans<<' ';
	    c=0;b=0;
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1')
	        {
	            v.pb(i+1);
	            c=1;
	        }

	    }
	    v.pb(n+1);
	    for(int i=0;i<v.size()-1;i++)
	    {
	       // cout<<v[i]<<' ' << v[i+1]<<endl;
	        x=v[i+1]-v[i]-1;
	        ans+=x/(2*k+1);
	    }
	   // if(c==0 && ans==0)
	   // ans=1;
	    cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll fast(ll x,ll n,ll mod){ll ans=1;while(n>0){if(n%2==1){ans = (ans* x)%mod;}x=x*x;x=x%mod;n=n/2;}return ans%mod;}
ll modi(ll a,ll mod){return fast(a,mod -2,mod);}
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	    ll n ,a[100005],b=0,c=0,ans=0,x,k;
	    string s;
	    vector<ll>v;
	    cin>>n>>k;
	    cin>>s;
	    v.pb(0);
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1' && b==0)
	        {
	            if(i>k)
	            {
	                s[0]='1';
	                ans++;
	            }
	            break;
	        }
	    }

	    for(int i=0;i<n;i++)
	    {
	        if(s[n-i-1]=='1' &&c==0)
	        {
	            if(i>k)
	            {
	                s[n-i-1]=='1';
	                ans++;
	            }
	            break;
	        }
	    }
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1' && b==0)
	        {
	            b=1;
	            break;
	        }
	    }
	    if(b==0)
	    {
	        s[0]='1';
	        ans++;
	        if(n>2*k)
	        {
	            s[n-1]='1';
	            ans++;
	        }
	    }
	   // cout<<ans<<' ';
	    c=0;b=0;
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1')
	        {
	            v.pb(i+1);
	            c=1;
	        }

	    }
	    v.pb(n+1);
	    for(int i=0;i<v.size()-1;i++)
	    {
	       // cout<<v[i]<<' ';
	        x=v[i+1]-v[i]-1;
	        ans+=x/(2*k+1);
	    }
	   // if(c==0 && ans==0)
	   // ans=1;
	    cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll fast(ll x,ll n,ll mod){ll ans=1;while(n>0){if(n%2==1){ans = (ans* x)%mod;}x=x*x;x=x%mod;n=n/2;}return ans%mod;}
ll modi(ll a,ll mod){return fast(a,mod -2,mod);}
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	    ll n ,a[100005],b=0,c=0,ans=0,x,k;
	    string s;
	    vector<ll>v;
	    cin>>n>>k;
	    cin>>s;
	    v.pb(0);
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1' && b==0)
	        {
	            if(i>k)
	            {
	                s[0]='1';
	                ans++;
	            }
	            break;
	        }
	    }

	    for(int i=0;i<n;i++)
	    {
	        if(s[n-i-1]=='1' &&c==0)
	        {
	            if(i>k)
	            {
	               // cout<<'a';
	                s[n-1]='1';
	                ans++;
	            }
	            break;
	        }
	    }
	   // cout<<s<<endl;
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1' && b==0)
	        {
	            b=1;
	            break;
	        }
	    }
	    if(b==0)
	    {
	        s[0]='1';
	        ans++;
	        if(n>2*k)
	        {
	            s[n-1]='1';
	            ans++;
	        }
	    }
	   // cout<<ans<<' ';
	    c=0;b=0;
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1')
	        {
	            v.pb(i+1);
	            c=1;
	        }

	    }
	    v.pb(n+1);
	    for(int i=0;i<v.size()-1;i++)
	    {
	       // cout<<v[i]<<' ' << v[i+1]<<endl;
	        x=v[i+1]-v[i]-1;
	        ans+=x/(2*k+1);
	    }
	   // if(c==0 && ans==0)
	   // ans=1;
	    cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll fast(ll x,ll n,ll mod){ll ans=1;while(n>0){if(n%2==1){ans = (ans* x)%mod;}x=x*x;x=x%mod;n=n/2;}return ans%mod;}
ll modi(ll a,ll mod){return fast(a,mod -2,mod);}
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	    ll n ,a[100005],b=0,c=0,ans=0,x,k;
	    string s;
	    vector<ll>v;
	    cin>>n>>k;
	    cin>>s;
	    v.pb(0);
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1' && b==0)
	        {
	            if(i+1>2*k)
	            {
	                s[0]='1';
	                ans++;
	            }
	            break;
	        }
	    }

	    for(int i=0;i<n;i++)
	    {
	        if(s[n-i-1]=='1' &&c==0)
	        {
	            if(i+1>2*k)
	            {
	                s[n-i-1]=='1';
	                ans++;
	            }
	            break;
	        }
	    }
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1' && b==0)
	        {
	            b=1;
	            break;
	        }
	    }
	    if(b==0)
	    {
	        s[0]='1';
	        ans++;
	        if(n>2*k)
	        {
	            s[n-1]='1';
	            ans++;
	        }
	    }
	   // cout<<ans<<' ';
	    c=0;b=0;
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1')
	        {
	            v.pb(i+1);
	            c=1;
	        }

	    }
	    v.pb(n+1);
	    for(int i=0;i<v.size()-1;i++)
	    {
	       // cout<<v[i]<<' ';
	        x=v[i+1]-v[i]-1;
	        ans+=x/(2*k+1);
	    }
	   // if(c==0 && ans==0)
	   // ans=1;
	    cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll fast(ll x,ll n,ll mod){ll ans=1;while(n>0){if(n%2==1){ans = (ans* x)%mod;}x=x*x;x=x%mod;n=n/2;}return ans%mod;}
ll modi(ll a,ll mod){return fast(a,mod -2,mod);}
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	    ll n ,a[100005],b=0,c=0,ans=0,x,k;
	    string s;
	    vector<ll>v;
	    cin>>n>>k;
	    cin>>s;
	    v.pb(0);
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1')
	        {
	            v.pb(i+1);
	            c=1;
	        }

	    }
	    v.pb(n+1);
	    for(int i=0;i<v.size()-1;i++)
	    {
	       // cout<<v[i]<<' ';
	        x=v[i+1]-v[i]-1;
	        ans+=x/(k+1);
	    }
	    if(c==0 && ans==0)
	    ans=1;
	    cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll fast(ll x,ll n,ll mod){ll ans=1;while(n>0){if(n%2==1){ans = (ans* x)%mod;}x=x*x;x=x%mod;n=n/2;}return ans%mod;}
ll modi(ll a,ll mod){return fast(a,mod -2,mod);}
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	    ll n ,a[100005],b=0,c=0,ans=0,x,k;
	    string s;
	    vector<ll>v;
	    cin>>n>>k;
	    cin>>s;
	    v.pb(-k-1);
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1')
	        v.pb(i+1);
	    }
	    v.pb(n+k + 1);
	    for(int i=0;i<v.size()-1;i++)
	    {
	       // cout<<v[i]<<' '<<v[i+1]<<' ';
	        x=v[i+1]-v[i]-1;

	        ans+=x/(2*k+1);
	    }
	   // if(c==0 && ans==0)
	   // ans=1;
	    cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fastinputoutput ios_base::sync_with_stdio(false);cin.tie(NULL);
ll fast(ll x,ll n,ll mod){ll ans=1;while(n>0){if(n%2==1){ans = (ans* x)%mod;}x=x*x;x=x%mod;n=n/2;}return ans%mod;}
ll modi(ll a,ll mod){return fast(a,mod -2,mod);}
int main() {
	fastinputoutput;
	int t;
	cin>>t;
	while(t--)
	{
	    int n,k,cnt=0,p=0;
	    string s,s2;
	    cin>>n>>k>>s;
	    p=-k -1;
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='0')
	        {
	            if(i-p>k)
	            {
	                p=i;
	                cnt++;
	            }
	        }
	        if(s[i]=='1')
	        {
	            if(i-p<=k && i!=0)
	            {
	                cnt--;
	            }
	            p=i;
	        }
	    }
	    cout<<cnt<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll fast(ll x,ll n,ll mod){ll ans=1;while(n>0){if(n%2==1){ans = (ans* x)%mod;}x=x*x;x=x%mod;n=n/2;}return ans%mod;}
ll modi(ll a,ll mod){return fast(a,mod -2,mod);}
int main() {
	int t;
	cin>>t;
	while(t--)
	{
	    ll n ,a[100005],b=0,c=0,ans=0,x,k;
	    string s;
	    vector<ll>v;
	    cin>>n>>k;
	    cin>>s;
	    v.pb(0);
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1' && b==0)
	        {
	            if(i>k)
	            {
	                s[0]='1';
	                ans++;
	            }
	            break;
	        }
	    }

	    for(int i=0;i<n;i++)
	    {
	        if(s[n-i-1]=='1' &&c==0)
	        {
	            if(i>k)
	            {
	               // cout<<'a';
	                s[n-1]='1';
	                ans++;
	            }
	            break;
	        }
	    }
	   // cout<<s<<endl;
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1' && b==0)
	        {
	            b=1;
	            break;
	        }
	    }
	    if(b==0)
	    {
	        s[0]='1';
	        ans++;
	        if(n-1>k)
	        {
	            s[n-1]='1';
	            ans++;
	        }
	    }
	   // cout<<ans<<' ';
	    c=0;b=0;
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='1')
	        {
	            v.pb(i+1);
	            c=1;
	        }

	    }
	    v.pb(n+1);
	    for(int i=0;i<v.size()-1;i++)
	    {
	       // cout<<v[i]<<' ' << v[i+1]<<endl;
	        x=v[i+1]-v[i]-1;
	        if(x>k+1)
	        ans+=x/(k+1) - 1;
	    }
	   // if(c==0 && ans==0)
	   // ans=1;
	    cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fastinputoutput ios_base::sync_with_stdio(false);cin.tie(NULL);
ll fast(ll x,ll n,ll mod){ll ans=1;while(n>0){if(n%2==1){ans = (ans* x)%mod;}x=x*x;x=x%mod;n=n/2;}return ans%mod;}
ll modi(ll a,ll mod){return fast(a,mod -2,mod);}
int main() {
	fastinputoutput;
	int t;
	cin>>t;
	while(t--)
	{
	    int n,k,cnt=0,p=0;
	    string s,s2;
	    cin>>n>>k>>s;
	    p=-k -1;
	    for(int i=0;i<n;i++)
	    {
	        if(s[i]=='0')
	        {
	            if(i-p>k)
	            {
	                p=i;
	                cnt++;
	            }
	        }
	        if(s[i]=='1' && i!=0)
	        {
	            if(i-p<=k)
	            {
	                cnt--;
	            }
	            p=i;
	        }
	    }
	    cout<<cnt<<endl;
	}
	return 0;
}


#include <iostream>
#define ll long long int
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,x=0,flag=0;
       string s;
       cin>>n>>k;
       cin>>s;
       int i=0;
       if(n==k)
       {
           cout<<0<<endl;
           continue;
       }
       while(i<n)
       {
            if(s[i]=='1' && i+k+1<n)
            {
                i=i+k+1;
            }
            else
            {
                 flag=0;
                if(s[i]=='0')
                {
                    int p=0;
                    while(p<k)
                    {
                        i++;
                        p++;
                        if(s[i]=='1')
                        {
                            flag=1;
                            break;
                        }
                    }
                    if(flag==0)
                    {
                        x++;
                    }
                }
            }
            i++;
       }
       cout<<x<<endl;
    }
return 0;
}


#include <iostream>
#define ll long long int
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,x=0,flag=0;
       string s;
       cin>>n>>k;
       cin>>s;
       int i=0;
       while(i<n)
       {
            if(s[i]=='1' && i+k<n)
            {
                i=i+k;
            }
            else
            {
                 flag=0;
                if(s[i]=='0')
                {
                    int p=0;
                    int y=i;
                    while(p<k && i<n)
                    {
                        i++;
                        y--;
                        p++;
                        if(y>=0 && i<n)
                        {
                            if(s[i]=='1' || s[y]=='1')
                        {
                            i--;
                            flag=1;
                            break;
                        }
                        }
                        else if(y<0 && i<n)
                        {
                            if(s[i]=='1')
                        {
                            i--;
                            flag=1;
                            break;
                        }
                        }
                        else if(y>=0 && i>=n)
                        {
                            if(s[y]=='1')
                        {
                            i--;
                            flag=1;
                            break;
                        }
                        }
                        else
                        {
                        continue;
                        }
                    }

                    if(flag==0)
                    {
                        s[i-k]='1';
                        x++;
                    }
                }
            }
            i++;
            cout<<i<<endl;
       }
       cout<<x<<endl;
    }
return 0;
}


#include <iostream>
#define ll long long int
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,x=0,flag=0;
       string s;
       cin>>n>>k;
       cin>>s;
       int i=0;
       while(i<n)
       {
            if(s[i]=='1' && i+k<n)
            {
                i=i+k;
            }
            else
            {
                 flag=0;
                if(s[i]=='0')
                {
                    int p=0;
                    int y=i;
                    while(p<k && i<n)
                    {
                        i++;
                        y--;
                        p++;
                        if(y>=0 && i<n)
                        {
                            if(s[i]=='1' || s[y]=='1')
                        {
                            i--;
                            flag=1;
                            break;
                        }
                        }
                        else if(y<0 && i<n)
                        {
                            if(s[i]=='1')
                        {
                            i--;
                            flag=1;
                            break;
                        }
                        }
                        else if(y>=0 && i>=n)
                        {
                            if(s[y]=='1')
                        {
                            i--;
                            flag=1;
                            break;
                        }
                        }
                        else
                        {
                        continue;
                        }
                    }

                    if(flag==0)
                    {
                        s[i-k]='1';
                        x++;
                    }
                }
            }
            i++;
       }
       cout<<x<<endl;
    }
return 0;
}


#include <iostream>
#define ll long long int
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,x=0,flag=0;
       string s;
       cin>>n>>k;
       cin>>s;
       int i=0;
       while(i<n)
       {
            if(s[i]=='1' && i+k+1<n)
            {
                i=i+k+1;
            }
            else
            {
                 flag=0;
                if(s[i]=='0')
                {
                    int p=0;
                    int y=i;
                    while(p<k && y>=0)
                    {
                        i++;
                        y--;
                        p++;
                        if(s[i]=='1' || s[y]=='1')
                        {
                            flag=1;
                            break;
                        }
                    }
                    if(flag==0)
                    {
                        x++;
                    }
                }
            }
            i++;
       }
       cout<<x<<endl;
    }
return 0;
}


#include <iostream>
#define ll long long int
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,x=0,flag=0;
       string s;
       cin>>n>>k;
       cin>>s;
       int i=0;
       while(i<n)
       {
            if(s[i]=='1' && i+k<n)
            {
                i=i+k;
            }
            else
            {
                 flag=0;
                if(s[i]=='0')
                {
                    int p=0;
                    int y=i;
                    while(p<k && i<n)
                    {
                        i++;
                        y--;
                        p++;
                        if(y>=0 && i<n)
                        {
                            if(s[i]=='1' || s[y]=='1')
                        {
                            flag=1;
                            break;
                        }
                        }
                        else if(y<0 && i<n)
                        {
                            if(s[i]=='1')
                        {
                            flag=1;
                            break;
                        }
                        }
                        else if(y>=0 && i>=n)
                        {
                            if(s[y]=='1')
                        {
                            flag=1;
                            break;
                        }
                        }
                        else
                        {
                        continue;
                        }
                    }

                    if(flag==0)
                    {
                        s[i-k]='1';
                        x++;
                    }
                }
            }
            i++;
       }
       cout<<x<<endl;
    }
return 0;
}


#include <iostream>
#define ll long long int
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,x=0,flag=0;
       string s;
       cin>>n>>k;
       cin>>s;
       int i=0;
       while(i<n)
       {
            if(s[i]=='1' && i+k+1<n)
            {
                i=i+k;
            }
            else
            {
                 flag=0;
                if(s[i]=='0')
                {
                    int p=0;
                    int y=i;
                    while(p<k)
                    {
                        i++;
                        y--;
                        p++;
                        if(y>=0)
                        {
                            if(s[i]=='1' || s[y]=='1')
                        {
                            flag=1;
                            break;
                        }
                        }
                        else
                        {
                            if(s[i]=='1')
                        {
                            flag=1;
                            break;
                        }
                        }
                    }

                    if(flag==0)
                    {
                        s[i]='1';
                        x++;
                    }
                }
            }
            i++;
       }
       cout<<x<<endl;
    }
return 0;
}


#include <iostream>
#define ll long long int
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,x=0,flag=0;
       string s;
       cin>>n>>k;
       cin>>s;
       int i=0;
       while(i<n)
       {
           if(s[i]=='1' && i+k>=n)
           {
               break;
           }
            if(s[i]=='1' && i+k<n)
            {
                i=i+k;
            }
            else
            {
                 flag=0;
                if(s[i]=='0')
                {
                    int p=0;
                    int y=i;
                    while(p<k && i<n)
                    {
                        i++;
                        y--;
                        p++;
                        if(y>=0 && i<n)
                        {
                            if(s[i]=='1' || s[y]=='1')
                        {
                            i--;
                            flag=1;
                            break;
                        }
                        }
                        else if(y<0 && i<n)
                        {
                            if(s[i]=='1')
                        {
                            i--;
                            flag=1;
                            break;
                        }
                        }
                        else if(y>=0 && i>=n)
                        {
                            if(s[y]=='1')
                        {
                            i--;
                            flag=1;
                            break;
                        }
                        }
                        else
                        {
                        continue;
                        }
                    }

                    if(flag==0)
                    {
                        s[i-k]='1';
                        x++;
                    }
                }
            }
            i++;
       }
       cout<<x<<endl;
    }
return 0;
}


#include <iostream>
#define ll long long int
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,x=0,flag=0;
       string s;
       cin>>n>>k;
       cin>>s;
       int i=0;
       while(i<n)
       {
            if(s[i]=='1' && i+k+1<n)
            {
                i=i+k;
            }
            else
            {
                 flag=0;
                if(s[i]=='0')
                {
                    int p=0;
                    int y=i;
                    while(p<k)
                    {
                        i++;
                        y--;
                        p++;
                        if(s[i]=='1' || s[y]=='1')
                        {
                            flag=1;
                            break;
                        }
                    }
                    if(flag==0)
                    {
                        s[i]='1';
                        x++;
                    }
                }
            }
            i++;
       }
       cout<<x<<endl;
    }
return 0;
}


#include <iostream>
#define ll long long int
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,x=0,flag=0;
       string s;
       cin>>n>>k;
       cin>>s;
       int i=0;
       while(i<n)
       {
            if(s[i]=='1' && i+k+1<n)
            {
                i=i+k+1;
            }
            else
            {
                 flag=0;
                if(s[i]=='0')
                {
                    int p=0;
                    while(p<k)
                    {
                        i++;
                        p++;
                        if(s[i]=='1')
                        {
                            flag=1;
                            break;
                        }
                    }
                    if(flag==0)
                    {
                        x++;
                    }
                }
            }
            i++;
       }
       cout<<x<<endl;
    }
return 0;
}


#include <iostream>
#define ll long long int
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,x=0,flag=0;
       string s;
       cin>>n>>k;
       cin>>s;
       int i=0;
       while(i<n)
       {
            if(s[i]=='1' && i+k<n)
            {
                i=i+k;
            }
            else
            {
                 flag=0;
                if(s[i]=='0')
                {
                    int p=0;
                    int y=i;
                    while(p<k && i<n)
                    {
                        i++;
                        y--;
                        p++;
                        if(y>=0)
                        {
                            if(s[i]=='1' || s[y]=='1')
                        {
                            flag=1;
                            break;
                        }
                        }
                        else
                        {
                            if(s[i]=='1')
                        {
                            flag=1;
                            break;
                        }
                        }
                    }

                    if(flag==0)
                    {
                        s[i]='1';
                        x++;
                    }
                }
            }
            i++;
       }
       cout<<x<<endl;
    }
return 0;
}


#include <iostream>
#define ll long long int
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,x=0,flag=0;
       string s;
       cin>>n>>k;
       cin>>s;
       int i=0;
       while(i<n)
       {
            if(s[i]=='1' && i+k+1<n)
            {
                i=i+k;
            }
            else
            {
                 flag=0;
                if(s[i]=='0')
                {
                    int p=0;
                    int y=i;
                    while(p<k && i<n)
                    {
                        i++;
                        y--;
                        p++;
                        if(y>=0)
                        {
                            if(s[i]=='1' || s[y]=='1')
                        {
                            flag=1;
                            break;
                        }
                        }
                        else
                        {
                            if(s[i]=='1')
                        {
                            flag=1;
                            break;
                        }
                        }
                    }

                    if(flag==0)
                    {
                        s[i]='1';
                        x++;
                    }
                }
            }
            i++;
       }
       cout<<x<<endl;
    }
return 0;
}


def calc(*argv):
    score=0
    for j in range(argv[1]):
        choix={'A':0,'B':0,'C':0,'D':0,'E':0}
        for i in range(argv[0]):
            choix[argv[2+i][j]]+=1

        score+=max(choix.values()) * argv[argv[0]+2][j]
    print(score)

calc


def calc(*argv):
    score=0
    for j in range(argv[1]):
        choix={'A':0,'B':0,'C':0,'D':0,'E':0}
        for i in range(argv[0]):
            choix[argv[2][i][j]]+=1

        score+=max(choix.values()) * argv[3][j]
    print(score)

#argv=[2,4,['ABCD','ABCE'],[1, 2, 3, 4]]
calc


def score(n,m,s,a):
    score=0
    for j in range(m):
        choix={'A':0,'B':0,'C':0,'D':0,'E':0}
        for i in range(n):
            choix[s[i][j]]+=1
        score+=max(choix.values()) * a[j]
    return score


def calc(*argv):
    score=0
    for j in range(argv[1]):
        choix={'A':0,'B':0,'C':0,'D':0,'E':0}
        for i in range(argv[0]):
            choix[argv[2+i][j]]+=1

        score+=max(choix.values()) * argv[argv[0]+2+j]
    print(score)

calc


def score(n,m,s,a):
	score=0
	for j in range(m):
		choix={'A':0,'B':0,'C':0,'D':0,'E':0}
		for i in range(n):
			choix[s[i][j]]+=1
		score+=max(choix) * a[j]
	return score


def calc(n,m,s,a):

    score=0
    for j in range(m):
        choix={'A':0,'B':0,'C':0,'D':0,'E':0}
        for i in range(n):
            choix[s[i][j]]+=1

        score+=max(choix.values()) * a[j]
    print(score)

l=input()
p=l.split(" ")
n,m=int(p[0]),int(p[1])
s=[]
for i in range(n):
    s.append(input())

l=input()
a=l.split(" ")
for i in range(m):
    a[i]=int(a[i])
calc(n,m,s,a)


def score(n,m,s,a):
    score=0
    for j in range(m):
        choix={'A':0,'B':0,'C':0,'D':0,'E':0}
        for i in range(n):
            choix[s[i][j]]+=1

        score+=max(choix.values()) * a[j]
    return score

print(score(n,m,s,a))


def score(n,m,s,a):
    score=0
    for j in range(m):
        choix={'A':0,'B':0,'C':0,'D':0,'E':0}
        for i in range(n):
            choix[s[i][j]]+=1
        # score+=max({i:j for i, j in choix.items()}.values()) * a[j]
        score+=max(choix.values()) * a[j]
    return score

score(n,m,s,a)


def score(n,m,s,a):
    score=0
    for j in range(m):
        choix={'A':0,'B':0,'C':0,'D':0,'E':0}
        for i in range(n):
            choix[s[i][j]]+=1
        score+=max(choix.values()) * a[j]
    return score

n=2
m=4
s=['ABCD','ABCE']
a=[1, 2, 3, 4]
print(score(n,m,s,a))

n=3
m=3
s=['ABC','BCD','CDE']
a=[5, 4, 12]
print(score(n,m,s,a))


# import numpy as np
print("ok")
def calc(*argv):
    score=0
    print("yes")
    for j in range(argv[1]):
        choix={'A':0,'B':0,'C':0,'D':0,'E':0}
        for i in range(argv[0]):
            choix[argv[2][i][j]]+=1
        score+=max(choix.values()) * argv[3][j]
    print(score)

argv=[2,4,['ABCD','ABCE'],[1, 2, 3, 4]]
calc(*argv)


def calc(*argv):
    score=0
    for j in range(argv[1]):
        choix={'A':0,'B':0,'C':0,'D':0,'E':0}
        for i in range(argv[0]):
            choix[argv[2][i][j]]+=1
        # score+=max({i:j for i, j in choix.items()}.values()) * a[j]
        score+=max(choix.values()) * argv[3][j]
    print(score)

argv=[2,4,['ABCD','ABCE'],[1, 2, 3, 4]]
calc(*argv)


def calc(n,m,s,a):

    score=0
    for j in range(m):
        choix={'A':0,'B':0,'C':0,'D':0,'E':0}
        for i in range(n):
            choix[s[i][j]]+=1

        score+=max(choix.values()) * a[j]
    print(score)

n=int(input())
m=int(input())
s=[]
for i in range(n):
    s.append(input())
a=[]
for j in range(m):
    a.append(int(input()))
calc(n,m,s,a)


from collections import Counter
def main():
    n,m = [int(i) for i in input().split()]
    s = [input() for i in range(n)]
    a = [int(i) for i in input().split()]
    s_zip = [[i[j] for i in s] for j in range(m)]
    freq = [Counter(i).most_common()[0][1] for i in s_zip]
    print(sum([a[i]*freq[i] for i in range(m)]))

main()


n,m=map(int,input().split())
l=[]
for i in range(n):
	l.append(list(input()))

ans=0

s=list(map(int,input().split()))
for i in range(m):
	a=[]
	p=[]
	mj=[]
	for j in range(n):
		a.append(l[j][i])
	for k in a:
		if(k not in mj):
			mj.append(k)
			p.append(a.count(k))  #5052 1368
	t=max(p)
	if(max(p)==1):
		ans+=s[i]
	else:
		ans+=t*s[i]
print(ans)


n,m=map(int,input().split())
l=[]
for i in range(n):
	l.append(list(input()))

ans=0

s=list(map(int,input().split()))
for i in range(m):
	a=[]
	p=[]
	for j in range(n):
		a.append(l[j][i])
	for k in a:
		p.append(a.count(k))
	t=p.count(max(p))
	if(max(p)==1):
		ans+=s[i]
	else:
		ans+=t*s[i]
print(ans)


n, m = map(int, input().split())
translate = {"A": 0, "B": 1, "C": 2, "D": 3, "E":4}
have = []
for i in range(m):
    have.append([0, 0, 0, 0, 0])
for i in range(n):
    st = input()
    for j in range(m):
        have[j][translate[st[j]]] += 1
value = list(map(int, input().split()))
total = 0
for i in range(m):
    total += max(have[i])*value[i]
print(total)


n, m = map(int, input().split())
have = []
for i in range(m):
    have.append([])
score = [1] * m
answer = input()
for i in range(m):
    have[i].append(answer[i])
for i in range(1, n):
    st = input()
    for j in range(m):
        if st[j] in have[j]:
            score[j] += 1
        else:
            have[j].append(st[j])
value = list(map(int, input().split()))
total = 0
for i in range(m):
    total += value[i] * score[i]
print(total)


n,m = map(int,input().split())
number = [[0 for i in range(1005)] for j in range(5)]
most_number = [0 for i in range(1005)]
for i in range(n):
    s = input()
    for j in range(m):
        number[j][ord(s[j]) - ord('A')] += 1
ans = 0
score = [int(i) for i in input().split()]
for i in range(m):
    most_number[i] = 0
    for j in range(5):
        if most_number[i] < number[i][j]:
            most_number[i] = number[i][j]
    ans += most_number[i] * score[i]
print(ans)


n, m = map(int, input().split())
number = []
for i in range(m):
    number.append([0, 0, 0, 0, 0])
for i in range(n):
    s = input()
    for j in range(m):
        number[j][ord(s[j])-65] += 1
max_number = []
for i in number:
    max_number.append(max(i))
score = list(map(int, input().split()))
ans = 0
for i in range(m):
    ans += score[i] * max_number[i]
print(ans)


n,m = [int(x) for x in input().split()]
l=[]
for i in range(m):
    l.append([0,0,0,0,0])
while n:
    n=n-1
    s = input()
    for i in range(0,len(s)):
        l[i][ord(s[i])-65] += 1
l1 = []
for i in l:
    l1.append(max(i))
l2 = list(map(int,input().split()))
print(sum(x * y for x, y in zip(l1,l2)))


n,m = map(int,input().split())
number = [[0 for i in range(1000)] for j in range(5)]
most_number = [0 for i in range(1000)]
for i in range(n):
    s = input()
    for j in range(m):
        number[j][ord(s[j]) - ord('A')] += 1
ans = 0
score = [int(i) for i in input().split()]
for i in range(m):
    most_number[i] = 0
    for j in range(5):
        if most_number[i] < number[i][j]:
            most_number[i] = number[i][j]
    ans += most_number[i] * score[i]
print(ans)


n,m=map(int,input().split())
a=[]
x=0
s=0
while x<n:
    a.append(input())
    x+=1
b=list(map(int,input().split()))
for i in range(m):
    s=s+max([a[j][i] for j in range(n)].count(h) for h in ["A","B","C","D","E"])*b[i]
print(s)


a, b = map(int, input().split())
y = []
counter = 0
for i in range(a):
    x = str(input())
    y.append(x)
points = list(map(int, input().split()))
for l in range(b):
    k = ""
    for j in range(a):
        s = y[j]
        k += s[l]
    w = []
    for e in k:
        w.append(k.count(e))
    counter += max(w)*points[l]
print(counter)

#tofmaal


IL = lambda: list(map(int, input().split()))

n, m = IL()
A = [input() for i in range(n)]
A = list(zip(*A))
V = IL()
print(sum(max(a.count(l) for l in a)*v for v, a in zip(V, A)))


from collections import Counter
IL = lambda: list(map(int, input().split()))

n, m = IL()
A = [input() for i in range(n)]
A = list(zip(*A))
V = IL()
print(sum(Counter(a).most_common(1)[0][1]*v for v, a in zip(V, A)))


for x in range(n):
    s.append(input())
a = [int (x) for x in input().split()]
i = 0
res = 0

for x in range(m):
    abcde = [0,0,0,0,0]
    for y in range(n):
        if(s[y][x] == 'A'):
            abcde[0] += 1
        elif(s[y][x] == 'B'):
            abcde[1] += 1
        elif(s[y][x] == 'C'):
            abcde[2] += 1
        elif(s[y][x] == 'D'):
            abcde[3] += 1
        else:
            abcde[4] += 1
    res += max(abcde)*a[i]
    i += 1
print(res)


n, m = [int (x) for x in input().split()]

s = []

for x in range(n):
    s.append(input())
a = [int (x) for x in input().split()]
i = 0
res = 0

for x in range(m):
    abcde = [0,0,0,0,0]
    for y in range(n):
        if(s[y][x] == 'A'):
            abcde[0] += 1
        elif(s[y][x] == 'B'):
            abcde[1] += 1
        elif(s[y][x] == 'C'):
            abcde[2] += 1
        elif(s[y][x] == 'D'):
            abcde[3] += 1
        else:
            abcde[4] += 1
    res += max(abcde)*a[i]
    i += 1
print(res)


n, m = [int (x) for x in input().split()]

s = []

for x in range(n):
    s.append(input())
a = [int (x) for x in input().split()]
i = 0
res = 0

for x in range(m):
    l = []
    countMax = 0
    vL = []
    for y in range(n):
        vL.append(s[y][x])
    for z in vL:
        if(vL.count(z) > countMax):
            countMax = vL.count(z)
    res += countMax*a[i]
    i += 1
print(res)


n, m = [int (x) for x in input().split()]

s = []

for x in range(n):
    s.append(input())
a = [int (x) for x in input().split()]
print(s)
i = 0
res = 0

for x in range(m):
    l = []
    countMax = 0
    vL = []
    for y in range(n):
        vL.append(s[y][x])
    for z in vL:
        if(vL.count(z) > countMax):
            countMax = vL.count(z)
    res += countMax*a[i]
    i += 1
print(res)


# import sys/2.out","w")
N=int(input())
L=list(map(int,input().split()))
L.sort()
for i in range(N-1):
	if L[i+1]>=L[i]:
		L[i+1]=L[i+1]-L[i]
		L[i]=0
	else:
		L[i+1]=L[i]-L[i+1]
		L[i]=0
FLAG=0
for i in L:
	if i!=0:
		FLAG=1
		break

if FLAG==1:
	print("NO")
else:
	print("YES")


# import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=open("output2.out","w")
n,m=map(int,input().split())
L=[]
ans=0
for i in range(n):
	L.append(list(input()))
Marks=list(map(int,input().split()))
for i in range(m):
	countA=0
	countB=0
	countC=0
	countD=0
	countE=0
	for j in range(n):
		if L[j][i]=='A':
			countA+=1
		if L[j][i]=='B':
			countB+=1
		if L[j][i]=='C':
			countC+=1
		if L[j][i]=='D':
			countD+=1
		if L[j][i]=='E':
			countE+=1
	ans+=max(countA,countB,countC,countD,countE)*Marks[i]
print(ans)


# import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=open("output2.out","w")
n,m=map(int,input().split())
L=[]
ans=0
for i in range(n):
	L.append(list(input()))
Marks=list(map(int,input().split()))
for i in range(m):
	countA=0
	countB=0
	countC=0
	countD=0
	countE=0
	for j in range(n):
		if L[j][i]=='A':
			countA+=1
		if L[j][i]=='B':
			countB+=1
		if L[j][i]=='C':
			countC+=1
		if L[j][i]=='D':
			countD+=1
		if L[j][i]=='A':
			countE+=1
	ans+=max(countA,countB,countC,countD,countE)*Marks[i]
print(ans)


from collections import Counter
n, m = map(int, input().split())
st = [input() for i in range(n)]
sc = [int(i) for i in input().split()]
ans = 0
for i in range(m):
    ans += sc[i] * max(Counter(s[i] for s in st).values())
print(ans)


import collections
n, m = map(int, input().split())
d = collections.defaultdict(list)
for _ in range(n):
    s = input()
    for i in range(m):
        d[i].append(s[i])
a = [int(i) for i in input().split()]
ans = 0
for i in range(m):
    mx = max(d[i], key=d[i].count)
    sm = d[i].count(mx)
    ans += sm * a[i]
print(ans)


n, m = map(int, input().split())
l = []
for x in range(n):
    l.append(input())
marks = list(map(int, input().split()))

question = 0
total = 0

while question < m:
    a_cou,b_cou,c_cou,d_cou,e_cou = 0, 0, 0, 0, 0
    for num in l:
        if num[question] == "A":
            a_cou += 1
        elif num[question] == "B":
            b_cou += 1
        elif num[question] == "C":
            c_cou += 1
        elif num[question] == "D":
            d_cou += 1
        else:
            e_cou += 1
    total += max(a_cou,b_cou,c_cou,d_cou,e_cou) * marks[question]
    question += 1
print(total)


n,m = map(int,input().split())
l = []
for x in range(n):
    l.append(input())
marks = list(map(int,input().split()))

student = 0
question = 0
correct_ans = 0
total = 0

while question < m:
    correct_ans = l[0][question]
    for num in l:
        if num[question] == correct_ans:
            student += 1
    total += student*marks[question]
    student = 0
    question += 1
print(total)


n,m = map(int, input().split())
all_ans = []
for i in range(n):
    ans = input()
    all_ans.append(ans)

scores = list(map(int, input().split()))

ans = 0

for i in range(m):
    dic = {'A':0, 'B': 0, 'C': 0, 'D': 0, 'E':0}
    for j in range(0, n):
        dic[all_ans[j][i]] += 1
    max_c = 1;
    max_c = max(max_c, dic['A'], dic['B'], dic['C'], dic['D'], dic['E'])
    ans += max_c * scores[i]

print(ans)


n,m = map(int, input().split())
all_ans = []
for i in range(n):
    ans = input()
    all_ans.append(ans)

scores = list(map(int, input().split()))
ans = 0
for i in range(m):
    same = 1
    prev = all_ans[0][i]
    for j in range(1, n):
        if all_ans[j][i] == prev: same += 1
    ans += same * scores[i]

print(ans)


import collections

n, m = list(map(int, input().split()))
options = [ input() for i in range(n)]
marks = list(map(int, input().split()))

total_marks = 0

for i in range(0, m):
    cnt = collections.Counter()
    for student in options:
        cnt[student[i]] += 1

    total_marks += max(cnt.values()) * marks[i]

print(total_marks)


n,m=input().split(" ")
a=int(n)
b=int(m)
l1=[]
l2=[]
l3=[]
for i in range(a):
    s=input()
    l1.append(s)
c=input()
l3=c.split(" ")
for i in l3:
    l2.append(int(i))
x=0
for j in range(len(l1)-1):
    for i in range(len(l1[j])):
        if l1[j][i] == l1[j+1][i]:
            x=x+(2*l2[i])
        else:
            x=x+l2[i]
if a>=3:
    x=x/(a-1)
print(int(x))


n, m = map(int, input().split())
s = []
ans = []
for i in range(n):
    s.append(input())
z = list(map(int, input().split()))
i = 0
while i != m:
    a = 0
    b = 0
    c = 0
    d = 0
    e = 0
    for j in s:
        if j[i] == 'A':
            a += 1
        if j[i] == 'B':
            b += 1
        if j[i] == 'C':
            c += 1
        if j[i] == 'D':
            d += 1
        if j[i] == 'E':
            e += 1
    if max(a, b, c, d, e) == a:
        ans.append('A')
    elif max(a, b, c, d, e) == b:
        ans.append('B')
    elif max(a, b, c, d, e) == c:
        ans.append('C')
    elif max(a, b, c, d, e) == d:
        ans.append('D')
    elif max(a, b, c, d, e) == e:
        ans.append('E')
    i += 1
balov = 0
for i in s:
    for j in range(len(i)):
        if i[j] == ans[j]:
            balov += z[j]
print(balov)


n, m = map(int, input().split())
s = []
ans = []
for i in range(n):
    s.append(input())
z = list(map(int, input().split()))
q = {k: [] for k in range(m)}
for i in s:
    for j in range(m):
        q[j].append(i[j])
for i in q.values():
    a = i.count('A')
    b = i.count('B')
    c = i.count('C')
    d = i.count('D')
    e = i.count('E')
    if max(a, b, c, d, e) == a:
        ans.append('A')
    elif max(a, b, c, d, e) == b:
        ans.append('B')
    elif max(a, b, c, d, e) == c:
        ans.append('C')
    elif max(a, b, c, d, e) == d:
        ans.append('D')
    elif max(a, b, c, d, e) == e:
        ans.append('E')
balov = 0
for i in s:
    for j in range(len(i)):
        if i[j] == ans[j]:
            balov += z[j]
print(balov)


n = input()
n=n.split( )
a=[]
#inting
for i in n:
    a.extend([int(i)])
ans=[]
listans=[]
ques=[]
#makinglistofit
for i in range(a[0]):
    sub=input()
    ans.extend([sub])
print(ans)
score = input()
score=score.split( )
scores=[]
for i in score:
    scores.extend([int(i)])
print(score)

for j in range(a[0]):
    holder2=[]
    holder2.clear()
    for i in ans[j]:
        holder2.extend([i])
        print(i)
    listans.extend([holder2])
    print(listans)

print(listans)

for c in range(a[1]):
    tracker=0
    holder={}
    letterlist=[]
    lib={"A":0,"B":0,"C":0,"D":0,"E":0}
    holder.clear()
    letterlist.clear()
    for i in range(a[0]):
        letter=ans[i][c]
        letterlist.extend([letter])
    for b in letterlist:
        lib[b]+=1
    max_key = max(lib, key=lib.get)
    holder=lib[max_key]
    print(letterlist)
    print(holder)
    ques.extend([holder])

print(ques)
points=0
for i in range(a[1]):
    points+=ques[i]*scores[i]

print(points)


n = input()
n=n.split( )
a=[]
#inting
for i in n:
    a.extend([int(i)])
ans=[]
listans=[]
ques=[]
#makinglistofit
for i in range(a[0]):
    sub=input()
    ans.extend([sub])

score = input()
score=score.split( )
scores=[]
for i in score:
    scores.extend([int(i)])

for j in range(a[0]):
    holder2=[]
    holder2.clear()
    for i in ans[j]:
        holder2.extend([i])

    listans.extend([holder2])

for c in range(a[1]):
    tracker=0
    holder={}
    letterlist=[]
    lib={"A":0,"B":0,"C":0,"D":0,"E":0}
    holder.clear()
    letterlist.clear()
    for i in range(a[0]):
        letter=ans[i][c]
        letterlist.extend([letter])
    for b in letterlist:
        lib[b]+=1
    max_key = max(lib, key=lib.get)
    holder=lib[max_key]

    ques.extend([holder])

points=0
for i in range(a[1]):
    points+=ques[i]*scores[i]

print(points)


if __name__ == "__main__" :
    n, m = map(int, input().split())
    responses, marks, ans = [input() for i in range(n)], [int(num) for num in input().split()], 0
    arr = [[] for i in range(m)]
    for i in range(m) :
        for j in range(n) :
            arr[i].append(responses[j][i])
    for i in range(m) :
        ans += (max(arr[i].count('A'), arr[i].count('B'), arr[i].count('C'), arr[i].count('D'), arr[i].count('E')))*marks[i]
    print(ans)


n,m=list(map(int,input().split()))
l1=[]
for i in range(n):
    s.append(input().strip())
a=list(map(int,input().split()))
res=0
for i in range(m):
    A,B,C,D,E=0,0,0,0,0
    for j in range(n):
        if l1[i][j]=='A':
            A+=1
        if l1[i][j]=='B':
            B+=1
        if l1[i][j]=='C':
            C+=1
        if l1[i][j]=='D':
            D+=1
        if l1[i][j]=='E':
            E+=1
    res+=max([A,B,C,D,E])*a[i]
print(res)


n,m=list(map(int,input().split()))
for i in range(n):
    ch=input.split()
for ele in range(m):
    a=list(map(int,input().split()))
ans=0
for x in a:
    ans+=x
print(ans)


n,m=list(map(int,input().split()))
for i in range(n):
    ch=input().split()
for ele in range(m):
    a=list(map(int,input().split()))
ans=0
for x in a:
    ans+=x
print(ans)


n,m=list(map(int,input().split()))
for i in range(n):
    ch=input().split()
for ele in range(m):
    a=list(map(int,input().split()))
ans=0
for x in a:
    ans+=int(x)
print(ans)


n,m=list(map(int,input().split()))
l1=[]
for i in range(n):
    s.append(input().strip())
a=list(map(int,input().split()))
res=0
for i in range(m):
    A,B,C,D,E=0,0,0,0,0
    for j in range(n):
        if l1[j][i]=='A':
            A+=1
        if l1[j][i]=='B':
            B+=1
        if l1[j][i]=='C':
            C+=1
        if l1[j][i]=='D':
            D+=1
        if l1[j][i]=='E':
            E+=1
    res+=max([A,B,C,D,E])*a[i]
print(res)


n,m=list(map(int,input().split()))
l1=[]
for i in range(n):
    s.append(input().strip())
a=list(map(int,input().split()))
res=0
for i in range(m):
    A,B,C,D,E=0,0,0,0,0
    for j in range(n):
        if l1[i][j]=='A':
            A+=1
        if l1[i][j]=='B':
            B+=1
        if l1[i][j]=='C':
            C+=1
        if l1[i][j]=='D':
            D+=1
        if l1[i][j]=='E':
            E+=1
    res+=max(A,B,C,D,E)*a[i]
print(res)


n,m=list(map(int,input().split()))
l1=[]
for i in range(n):
    l1.append(input().strip())
a=list(map(int,input().split()))
res=0
for i in range(m):
    A,B,C,D,E=0,0,0,0,0
    for j in range(n):
        if l1[j][i]=='A':
            A+=1
        if l1[j][i]=='B':
            B+=1
        if l1[j][i]=='C':
            C+=1
        if l1[j][i]=='D':
            D+=1
        if l1[j][i]=='E':
            E+=1
    res+=max(A,B,C,D,E)*a[i]
print(res)


n,m=list(map(int,input().split()))
l1=[]
for i in range(n):
    l1.append(input().strip())
a=list(map(int,input().split()))
res=0
for i in range(m):
    A,B,C,D,E=0,0,0,0,0
    for j in range(n):
        if l1[i][j]=='A':
            A+=1
        if l1[i][j]=='B':
            B+=1
        if l1[i][j]=='C':
            C+=1
        if l1[i][j]=='D':
            D+=1
        if l1[i][j]=='E':
            E+=1
    res+=max([A,B,C,D,E])*a[i]
print(res)


K,N= map(int,input().split())
List = []
for i in range(K):
    temp = input()
    List.append(temp)
Cost = [int(x) for x in input().split()]
Ans = 0
x = 0
Max = 0
for i in range(N):
    X = []
    for j in range(len(List)):
        X.append(List[j][i])
    Ans+=Cost[i] * X.count(max(X))

print(Ans)


from collections import defaultdict
K,N= map(int,input().split())
List = []
for i in range(K):
    temp = input()
    List.append(temp)
Cost = [int(x) for x in input().split()]
Ans = 0

for i in range(N):
    X = []
    Dict = defaultdict(int)
    for j in range(len(List)):
        X.append(List[j][i])
    for p in X:
        Dict[p]+=1
    Max = 0
    for t in Dict.keys():
        Max = max(Max,Dict[t])
    Ans+=Cost[i] * Max
print(Ans)


from collections import Counter

if __name__ == '__main__':
    R1 = lambda: list(map(int, input().split()))
    R2 = lambda: int(input())
    n, m = R1()
    results = [input() for _ in range(n)]
    values = R1()
    res = 0
    for i in range(m):
        res += values[i] * max(Counter(s[i] for s in results).values())
    print(res)


from collections import Counter
n,m = map(int,input().split())
s = [input() for _ in range(n)]
s = [*zip(*s)]
a = [*map(int,input().split())]
s = 0
for x, y in zip(map(Counter, s), a):
    s+=x.most_common(1)[0][1]*y
print(s)


from collections import Counter
n,m = map(int,input().split())
s = [input() for _ in range(n)]
s = [*zip(*s)]
a = [*map(int,input().split())]
val = 0
for x, y in zip(map(Counter, s), a):
    val+=x.most_common(1)[0][1]*y
print(val)


n,m=map(int,input().split())
list1=[]
for i in range(n) :
    list1.append(list(input()))

marks=list(map(int,input().split()))
d={}

for j in range(0,m) :
    d.update({j+1:[0,0,0,0,0]})
    for i in range(n) :
        if(list1[i][j]=="A") :
            d[j+1][0]+=1
        elif(list1[i][j]=="B") :
            d[j+1][1]+=1
        elif(list1[i][j]=="C") :
            d[j+1][2]+=1
        elif(list1[i][j]=="D") :
            d[j+1][3]+=1
        elif(list1[i][j]=="E") :
            d[j+1][4]+=1
total=0
for i in range(m) :
    total+= marks[i]*max(d[i+1])

print(total)


n,m=map(int,input().split())
list1=[]
for i in range(n) :
    list1.append(list(input()))

marks=list(map(int,input().split()))
d={}

for j in range(0,m) :
    d.update({j+1:[0,0,0,0,0]})
    for i in range(n) :
        if(list1[i][j]=="A") :
            d[j+1][0]+=1
        if(list1[i][j]=="B") :
            d[j+1][1]+=1
        if(list1[i][j]=="C") :
            d[j+1][2]+=1
        if(list1[i][j]=="D") :
            d[j+1][3]+=1
        if(list1[i][j]=="E") :
            d[j+1][4]+=1
total=0
for i in range(m) :
    total+= marks[i]*max(d[i+1])

print(total)


n,m=map(int,input().split())
answers=[]
for i in range(n) :
    answers.append(list(input()))
marks=list(map(int,input().split()))
d={}
for j in range(0,m) :
    d.update({j+1:[0,0,0,0,0]})
    for i in range(n) :
        if(list1[j][i]=="A") :
            d[j+1][1]+=1
        if(list1[j][i]=="B") :
            d[j+1][2]+=1
        if(list1[j][i]=="C") :
            d[j+1][3]+=1
        if(list1[j][i]=="D") :
            d[j+1][4]+=1
        if(list1[j][i]=="E") :
            d[j+1][5]+=1

for i in range(m) :
    total+= marks[i]*max(d[i+1])

print(total)


import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
import io
import os
##import operator
input=sys.stdin.readline
##input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import random
##sys.setrecursionlimit(10**7)
##fo=open("output.txt","w")
##fi=open("input2.txt","w")
mo=10**9+7
def cin():
    return map(int,sin().split())
def ain():
    return list(map(int,sin().split()))
def sin():
    return input()
def inin():
    return int(input())
for _ in range(1):
    n,m=cin()
    d=dd(dict)
    for i in range(n):
        s=sin()
        for j in range(m):
            d[j][s[j]]=d[j].get(s[j],0)+1
    l=ain();ans=0
    for i in range(m):
        ans+=l[i]*max(d[i].values())
    print(ans)


##################
# 6th August 2019.
##################

####################################################################
# Collecting Student and Question Counts.
students,questions = tuple(map(int,input().split(' ')))
# Setting-up Hash-Map for each Question.
questionMaps = []
def getQuestionMap():
    return {'A':0,'B':0,'C':0,'D':0,'E':0}
for i in range(questions):
    questionMaps.append(getQuestionMap())
# Collecting responses for each question.
for i in range(students):
    answerSheet = input()
    for j in range(questions):
        questionMaps[j][answerSheet[j]]+=1
# Determining Answer Sheet yielding maximum score.
def findAnswerFor(thisMap):
    maxCount = 0
    for letter in 'ABCDE':
        maxCount = max(maxCount,thisMap[letter])
    return maxCount
# Collecting points for each question.
points = tuple(map(int,input().split(' ')))
# Solution.
classScore = 0
for i in range(questions):
    classScore+=findAnswerFor(questionMaps[i])*points[i]
print(classScore)
####################################################################

                            ########################################
                            # Programming-Credits atifcppprogrammer.
                            ########################################


# Collecting Student and Question Counts.
students,questions = tuple(map(int,input().split(' ')))
# Setting-up Hash-Map for each Question.
questionMaps = []
def getQuestionMap():
    return {'A':0,'B':0,'C':0,'D':0,'E':0}
for i in range(questions):
    questionMaps.append(getQuestionMap())
# Collecting responses for each question.
for i in range(students):
    answerSheet = input()
    for j in range(questions):
        questionMaps[j][answerSheet[j]]+=1
# Determining Answer Sheet yielding maximum score.
def findAnswerFor(thisMap):
    maxCount = 0
    for letter in 'ABCDE':
        maxCount = max(maxCount,thisMap[letter])
    return maxCount
# Collecting points for each question.
points = tuple(map(int,input().split(' ')))
# Solution.
classScore = 0
for i in range(questions):
    classScore+=findAnswerFor(questionMaps[i])*points[i]
print(classScore)


n, m = map(int, input().split())
score = 0
Marks0 = []
for i in range (m):
    Marks0.append([0, 0, 0, 0, 0])
for i in range (n):
    x = input()
    for j in range (m):
        answer = x[0]
        x = x[1: ]
        if answer == 'A':
            Marks0[j][0] += 1
        if answer == 'B':
            Marks0[j][1] += 1
        if answer == 'C':
            Marks0[j][2] += 1
        if answer == 'D':
            Marks0[j][3] += 1
        if answer == 'E':
            Marks0[j][4] += 1
Points = [int(s) for s in input().split()]
for k in range(m):
    Marks0[k] = max(Marks0[k])
    score += Marks0[k] * Points[k]
    k += 1
print(score)


n, m = map(int, input().split())
score = 0
Marks0 = []
for i in range (m):
    Marks0.append([0, 0, 0, 0, 0])
for i in range (n):
    x = input()
    for j in range (m):
        answer = x[0]
        x = x[2: ]
        if answer == 'A':
            Marks0[j][0] += 1
        if answer == 'B':
            Marks0[j][1] += 1
        if answer == 'C':
            Marks0[j][2] += 1
        if answer == 'D':
            Marks0[j][3] += 1
        if answer == 'E':
            Marks0[j][4] += 1
k = 0
for i in Marks0:
    Marks0[k] = max(i)
    k += 1
x = input()
for i in Marks0:
    mark = int(x[0])
    x = x[2:]
    score += i * mark
print(score)


from sys  import stdin,stdout

import bisect

import math

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
            n=n-1
        else:
            a=(a*a)
            n=n>>1
    return r

def solve():
    n,m=mp()
    x=[]
    for i in range(n):
        s=st()
        x.append(s)
    l=li()
    c=0

    for i in range(m):
        d={}
        for j in range(n):

            d[x[j][i]]=d.get(x[j][i],0)+1

        a=max(d.values())
        c+=a*l[i]
    pr(c)

for _ in range(1):
    solve()


import math
import sys
import re

n , m = map(int , input().rstrip().split())
l1 = []
for x in range(n):
    s = input()
    l1.append(s)
l2 = list(map(int , input().rstrip().split()))
total = 0
for i in range(m):
    a = 0
    b = 0
    c = 0
    d = 0
    e = 0
    for j in l1:
        if j[i] == 'A':
            a = a + 1
        elif j[i] == 'B':
            b = b + 1
        elif j[i] == 'C':
            c = c + 1
        elif j[i] == 'D':
            d = d + 1
        elif j[i] == 'E':
            e = e + 1
    mx = max(a , b , c , d , e)
    total = total + mx*l2[i]
print(total)


from sys import stdin

def solve(a,c,n,m):
	i = 0
	ans = 0
	while i < m:
		j = 0
		t = [0 for _ in range(5)]
		mas = 0
		while j < n:
			x = ord(a[j][i])-65
			t[x]+=1
			if t[x] > mas:
				mas  = t[x]
			j+=1
		ans+= (c[i])*mas
		i+=1
	print(ans)

def main():
	n,m = map(int,stdin.readline().split())
	ans = list()
	for _ in range(n):
		ans.append(stdin.readline().strip())
	cor= list(map(int,stdin.readline().split()))
	solve(ans,cor,n,m)

main()


from sys import stdin

def solve(a,c,n,m):
	i = 0
	ans = 0
	while i < m:
		j = 0
		t = [0 for _ in range(5)]
		mas = [0,0]
		while j < n:
			x = ord(a[j][i])-65
			t[x]+=1
			if t[x] > mas[0]:
				mas[0] = t[x]
				mas[1] = x
			j+=1
		ans+= (c[mas[1]])*mas[0]
		i+=1
	print(ans)

def main():
	n,m = map(int,stdin.readline().split())
	ans = list()
	for _ in range(n):
		ans.append(stdin.readline().strip())
	cor= list(map(int,stdin.readline().split()))
	solve(ans,cor,n,m)

main()


import collections
import operator
nu=list(map(int,input().split(" ")))
n=nu[0]
m=nu[1]
ans=[]
for i in range(n):
	an=input()
	ans.append(an)

marks=list(map(int,input().split(" ")))
#print(ans)
#print(marks)
b=len(ans[0])

def add(temp):
	s=[]
	for i in range(0,len(temp)):
		s.append(temp[i][0])
	s1.append(s)

s1=[]
while(b!=0):
	add(ans)
	for i in range(len(ans)):
		ans[i]=ans[i][1:]
	b-=1
#print(s1)
mc=[]
for j in range(len(s1)):
	dd=dict(collections.Counter(s1[j]))
	mc.append(dd)
#print(mc)
for i in range(len(mc)):
	sorted_x = sorted(mc[i].items(), key=operator.itemgetter(1))
	mc[i]=sorted_x
#print(mc)
sum1=0
hh=0
for j in range(len(mc)):
	a=mc[j][0][1]
	sum1+=a*marks[hh]
	hh+=1
print(sum1)


import collections
import operator
nu=list(map(int,input().split(" ")))
n=nu[0]
m=nu[1]
ans=[]
for i in range(n):
	an=input()
	ans.append(an)

marks=list(map(int,input().split(" ")))
#print(ans)
#print(marks)
b=len(ans[0])

def add(temp):
	s=[]
	for i in range(0,len(temp)):
		s.append(temp[i][0])
	s1.append(s)

s1=[]
while(b!=0):
	add(ans)
	for i in range(len(ans)):
		ans[i]=ans[i][1:]
	b-=1
#print(s1)
mc=[]
for j in range(len(s1)):
	dd=dict(collections.Counter(s1[j]))
	mc.append(dd)
#print(mc)
for i in range(len(mc)):
	sorted_x = sorted(mc[i].items(), key=operator.itemgetter(1))
	mc[i]=sorted_x
#print(mc)
sum1=0
hh=0
for j in range(len(mc)):
	a=mc[j][len(mc[j])-1][1]
	#print(a,marks[hh])
	sum1+=a*marks[hh]
	hh+=1
print(sum1)


import collections
import operator
nu=list(map(int,input().split(" ")))
n=nu[0]
m=nu[1]
ans=[]
for i in range(n):
	an=input()
	ans.append(an)

marks=list(map(int,input().split(" ")))
#print(ans)
#print(marks)
b=len(ans[0])

def add(temp):
	s=[]
	for i in range(0,len(temp)):
		s.append(temp[i][0])
	s1.append(s)

s1=[]
while(b!=0):
	add(ans)
	for i in range(len(ans)):
		ans[i]=ans[i][1:]
	b-=1
#print(s1)
mc=[]
for j in range(len(s1)):
	dd=dict(collections.Counter(s1[j]))
	mc.append(dd)
#print(mc)
for i in range(len(mc)):
	sorted_x = sorted(mc[i].items(), key=operator.itemgetter(1))
	mc[i]=sorted_x
#print(mc)
sum1=0
hh=0
for j in range(len(mc)):
	a=mc[j][len(mc[j])-1][1]
	print(a,marks[hh])
	sum1+=a*marks[hh]
	hh+=1
print(sum1)


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
# import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def IF(c, t, f): return t if c else f
def YES(c): return IF(c, "YES", "NO")
def Yes(c): return IF(c, "Yes", "No")

def main():
    t = 1

    rr = []
    for _ in range(t):
        n,m = LI()
        sa = [S() for _ in range(n)]
        a = LI()

        r = 0
        for i,c in enumerate(a):
            t = collections.Counter(sa[j][i] for j in range(n))
            r += c * max(t.values())

        rr.append(r)

    return JA(rr, "\n")

print(main())


import operator
nm = [ int(x) for x in input().strip().split()]
answers={}
scores=[]
total = 0
for i in range(0,nm[0]):
    answers[i] = list(input().strip())

scores = [int(x) for x in input().strip().split()]
for i in range(0,nm[1]):
    ansdic = {"A":0 , "B":0 , "C":0, "D":0 , "E":0}
    for j in answers.keys():
        ansdic[answers[j][i]]+=1
    total += scores[i] * max(ansdic.values())
print(total)


a,b=map(int,input().split())
for _ in range(a):
    s=input()
arr=[int(i) for i in input().split()]
print(sum(arr))


a,b=map(int,input().split())
ss=[]
for _ in range(a):
    s=input()
    ss.append(s)
arr=[int(i) for i in input().split()]
doi=0
for i in range(b):
    arr1=[0]*5
    for j in range(a):
        arr1[ord(ss[j][i])-65]+=1
    doi+=max(arr1)*arr[i]
print(doi)


n,m=map(int,input().split())
w=[[0 for i in range(5)] for i in range(m)]
for i in range(n):
	s=input()
	for j in range(m):
		code=ord(s[j])-ord('A')
		w[j][code]+=1
print(w)
for i in range(m):
	w[i]=max(w[i])
print(w)
a=list(map(int,input().split()))
c=0
for i in range(m):
	c+=a[i]*w[i]
print(c)


n,m=map(int,input().split())
w=[[0 for i in range(5)] for i in range(m)]
for i in range(n):
	s=input()
	for j in range(m):
		code=ord(s[j])-ord('A')
		w[j][code]+=1
for i in range(m):
	w[i]=max(w[i])
a=list(map(int,input().split()))
c=0
for i in range(m):
	c+=a[i]*w[i]
print(c)


n,m=map(int,input().split())
a=[0]*m
b=[0]*m
c=[0]*m
d=[0]*m
e=[0]*m
sum=0
for _ in range(n):
    s=input()
    for i in range(m):
        if s[i]=="A":
            a[i]+=1
        elif s[i]=="B":
            b[i]+=1
        elif s[i]=="C":
            c[i]+=1
        elif s[i]=="D":
            d[i]+=1
        elif s[i]=="E":
            e[i]+=1
arr=[int(x) for x in input().split()]
for j in range(m):
    sum+=arr[j]*max(a[j],b[j],c[j],d[j],e[j])
print(sum)


n,m=map(int,input())
a=[0]*m
b=[0]*m
c=[0]*m
d=[0]*m
e=[0]*m
for _ in range(n):
    s=input()
    for i in range(m):
        if s[i]=="A":
            a[i]+=1
        elif s[i]=="B":
            b[i]+=1
        elif s[i]=="C":
            c[i]+=1
        elif s[i]=="D":
            d[i]+=1
        elif s[i]=="E":
            e[i]+=1
arr=[int(x) for x in input().split()]
for j in range(m):
    sum+=arr[j]*max(a[j],b[j],c[j],d[j],e[j])


n,m=map(int,input())
a=[0]*m
b=[0]*m
c=[0]*m
d=[0]*m
e=[0]*m
for _ in range(n):
    s=input()
    for i in range(m):
        if s[i]=="A":
            a[i]+=1
        elif s[i]=="B":
            b[i]+=1
        elif s[i]=="C":
            c[i]+=1
        elif s[i]=="D":
            d[i]+=1
        elif s[i]=="E":
            e[i]+=1
arr=[int(x) for x in input().split()]
for j in range(m):
    sum+=arr[j]*max(a[j],b[j],c[j],d[j],e[j])
print(sum)


n, m = map(int, input().split())
s = []

for i in range(n): s += [input()]

a = list(map(int, input().split()))

q = []

for i in range(m): q += [[r[i] for r in s]]

r = 0

i = 0
for c in q:
  r += a[i] * max(c.count("A"), c.count("B"), c.count("C"), c.count("D"), c.count("E"))
  i += 1

print(r)


n, m = map(int, input().split())
s = q = []

for i in range(n): s += [input()]

a = list(map(int, input().split()))

for i in range(m): q += [[r[i] for r in s]]

r = 0

i = 0
for c in q:
  r += a[i] * max(c.count("A"), c.count("B"), c.count("C"), c.count("D"), c.count("E"))
  i += 1

print(r)


i=lambda:map(int,input().split())
n,m=i();a=zip(*[input()for _ in[0]*n])
print(sum(y*max(map(''.join(x).count,'ABCDE')) for x,y in zip(a,i())))


i=lambda:map(int,input().split())
n,m=i();a=zip(*[input()for _ in[0]*n]);b=i()
print(sum(y*max(map(''.join(x).count,x)) for x,y in zip(a,b)))


from collections import Counter
n,m = list(map(int,input().split()))
a = [[0 for i in range(n)] for i in range(m)]
print(a)
for i in range(n):
    b = list(map(str,input()))
    for ind,el in enumerate(b):
        a[ind][i] = el

point = list(map(int,input().split()))
ans = 0
for i in range(m):
    ans += point[i]*(Counter(a[i]).most_common(1)[0][1])
print(ans)


from collections import Counter
n,m = list(map(int,input().split()))
a = [[0 for i in range(n)] for i in range(m)]
#print(a)
for i in range(n):
    b = list(map(str,input()))
    for ind,el in enumerate(b):
        a[ind][i] = el

point = list(map(int,input().split()))
ans = 0
for i in range(m):
    ans += point[i]*(Counter(a[i]).most_common(1)[0][1])
print(ans)


a, b = gets.split.map(&:to_i)
c = Array.new(a).map do
  gets.chomp.bytes
end
f = gets.split.map(&:to_i)
puts(
  c.transpose.zip(f).map do |d, i|
    i * d.uniq.map{ |e| d.count e }.max
  end.inject(:+)
)


n, m = STDIN.gets.chomp.split(" ").map(&:to_i)

freq = Array.new(m){ {'A' => 0, 'B' => 0, 'C' => 0, 'D' => 0, 'E' => 0} }

n.times do |i|
  line = STDIN.gets.chomp.each_char.with_index do |c, j|
    freq[j][c] += 1
  end
end

scores = STDIN.gets.chomp.split(" ").map(&:to_i)
puts freq.map.with_index{|f, i| f.values.max*scores[i]}.reduce(&:+)


n, m = gets.split.map &:to_i
s = []
n.times { s << gets.chomp }
b = m.times.map do |j|
  h = {}
  (0...n).each do |i|
    h[s[i][j]] ||= 0
    h[s[i][j]] += 1
  end
  h.values.max
end
puts gets.split.each_with_index.inject(0) { |s, x| s + x[0].to_i*b[x[1]] }


n, m = map(int, raw_input().split())

matriz = []

total = 0
for k in xrange(n):
	matriz.append(raw_input())

pontos = map(int, raw_input().split())

for i in xrange(len(matriz[0])):
	ba = [0, 0, 0, 0, 0]
	for k in xrange(len(matriz)):
		if matriz[k][i] == "A":
			ba[0] += 1
		if matriz[k][i] == "B":
			ba[1] += 1
		if matriz[k][i] == "C":
			ba[2] += 1
		if matriz[k][i] == "D":
			ba[3] += 1
		if matriz[k][i] == "E":
			ba[4] += 1

	total += max(ba) * pontos[i]

print total


n,m = map(int,raw_input().split())
q=[[0,0,0,0,0] for k in range(m)]
for i in range(n):
    a = raw_input()
    for j in range(m):
        q[j][ord(a[j])-65] += 1
s = map(int,raw_input().split())
total = 0
for c in range(m):
    total += s[c]*max(q[c])
print total


n, m = map(int, raw_input().split())
d = [[0, 0, 0, 0, 0] for i in xrange(m)]
for i in xrange(n):
    s = raw_input()
    for j in xrange(m):
        k = ord(s[j]) - 65
        d[j][k] += 1
a = map(int, raw_input().split())
c = 0
for i in xrange(m):
    c += max(d[i]) * a[i]
print c


from sys import stdin,stdout
I = lambda : map(int,stdin.readline().split())

n,m = I()
a = []
for i in range(n):
	a.append(map(ord,raw_input()))
# print a
sc = I()
ans = 0
for i in range(m):
	arr = [0]*5
	for j in range(n):
		arr[a[j][i] - 65]+=1
	# print arr
	ans+=sc[i]*max(arr)
print ans


from sys import stdin,stdout
I = lambda : map(int,stdin.readline().split())

n,m = I()
ans = raw_input()
a = []
for i in range(1,n):
	a.append(raw_input())
sc = I()
sm = sum(sc)
for j in a:
	for i in range(m):
		# print i,sc
		if ans[i] == j[i]:
			sm+=sc[i]
print sm


/*BINH :))*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long llu;
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f  first
#define s  second
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define sz(a) (int) a.size()
#define FOR(x,a,b) for (int x=a;x<=b;x++)
#define FOD(x,a,b) for (int x=a;x>=b;x--)
#define REP(x,a,b) for (int x=a;x<b;x++)
#define RED(x,a,b) for (int x=a;x>b;x--)
#define EL cout<<endl
#define ii pair<ll,ll>

void init(){
    freopen("dijkstra.inp","r",stdin);
    freopen("dijkstra.out","w",stdout);
}
ll n,m,a[1000000],l[1000000],x,y,z,buoc,r[1000000];
void solve(){
    ll n, k;
    cin >> n;
    FOR(i,1,n){
        cin >> a[i];
    }
    ll bob = 0,alice = 0,i = 1,j = n,a1=0,a2=0,turn = 0;
    while(i <= j){
        while(alice <= bob && i <= j) alice += a[i++];
        ++turn;
        bob = 0;
        a1 += alice;
        if(i > j) break;

        while(bob <= alice && i <= j) bob   += a[j--];
        ++turn;
        a2 += bob;
        alice = 0;
        if(i > j) break;

    }
    cout << turn << ' ' << a1 << ' ' << a2;EL;

}
int main(){
    IO
    ll t;
    cin >> t;
    while(t--) solve();
}


/*BINH :))*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long llu;
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f  first
#define s  second
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define sz(a) (int) a.size()
#define FOR(x,a,b) for (int x=a;x<=b;x++)
#define FOD(x,a,b) for (int x=a;x>=b;x--)
#define REP(x,a,b) for (int x=a;x<b;x++)
#define RED(x,a,b) for (int x=a;x>b;x--)
#define EL cout<<endl
#define ii pair<ll,ll>

void init(){
    freopen("dijkstra.inp","r",stdin);
    freopen("dijkstra.out","w",stdout);
}
ll n,m,a[1000000],l[1000000],x,y,z,buoc,r[1000000];
void solve(){
    ll n, k;
    cin >> n;
    FOR(i,1,n){
        cin >> a[i];
    }
    ll bob = 0,alice = 0,i = 1,j = n,a1=0,a2=0,turn = 0;
    while(i < j){
        while(alice <= bob && i < j) alice += a[i++];
        ++turn;
        bob = 0;
        a1 += alice;
        if(i > j) break;

        while(bob <= alice && i < j) bob   += a[j--];
        ++turn;
        a2 += bob;
        alice = 0;
        if(i > j) break;

    }
    cout << turn << ' ' << a1 << ' ' << a2;EL;

}
int main(){
    IO
    freopen("cf.inp","r",stdin);
    freopen("cf.out","w",stdout);
    ll t;
    cin >> t;
    while(t--) solve();
}


/*Winners never quit && Quitters never win*/
#include <iostream>
#include <deque>
using namespace std;
int t, n, a = 1, b = 1, x, j, k;
int ans, ansa, ansb;
deque <int> l;
bool h;
int main() {
	ios_base::sync_with_stdio();
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	while (t--) {
		cin >> n;
		if (n < 3) {
			if (n == 2) {
				cin >> x >> k;
				cout << n << " " << x << " " << k << endl;
			}
			else {
				cin >> x;
				cout << n << " " << x << " 0" << endl;
			}
		}
		else {
			for (int i = 0;i < n;i++) {
				cin >> x;
				l.push_back(x);
			}
			ansa += l[0];
			b += l[0];
			ans = 1;
			l.pop_front();
			h = true;
			while (h) {
				ans++;
				if (ans & 1) {
					while (a > 0) {
						if (l[j] <= a) {
							a -= l[j];
							ansa += l[j];
							b += l[j];
							l.pop_front();
						}
						else {
							b += l[j];
							ansa += l[j];
							l.pop_front();
							break;
						}
						if (l.size() == 0) {
							h = false;
							break;
						}
					}
					if (l.size() == 0) {
						h = false;
						break;
					}
					a = 1;
				}
				else {
					while (b > 0) {
						if (l.back() <= b) {
							b -= l.back();
							ansb += l.back();
							a += l.back();
							l.pop_back();
						}
						else {
							a += l.back();
							ansb += l.back();
							l.pop_back();
							break;
						}
						if (l.size() == 0) {
							h = false;
							break;
						}
					}
					if (l.size() == 0) {
						h = false;
						break;
					}
					b = 1;
				}
			}
			cout << ans << " " << ansa << " " << ansb << endl;
			ans = 0;
			ansa = 0;
			ansb = 0;
			a = 1;
			b = 1;
		}
	}
	return 0;
}


/*Winners never quit && Quitters never win*/
#include <iostream>
#include <deque>
using namespace std;
int t, n, a = 1, b = 1, x, j, k;
int ans, ansa, ansb;
deque <int> l;
bool h;
int main() {
	cin >> t;
	while (t--) {
		cin >> n;
		if (n < 3) {
			if (n == 2) {
				cin >> x >> k;
				cout << n << " " << x << " " << k << endl;
			}
			else {
				cin >> x;
				cout << n << " " << x << " 0" << endl;
			}
		}
		else {
			for (int i = 0;i < n;i++) {
				cin >> x;
				l.push_back(x);
			}
			ansa += l[0];
			b += l[0];
			ans = 1;
			l.pop_front();
			h = true;
			while (h) {
				ans++;
				if (ans & 1) {
					while (a > 0) {
						if (l[j] <= a) {
							a -= l[j];
							ansa += l[j];
							b += l[j];
							l.pop_front();
						}
						else {
							b += l[j];
							ansa += l[j];
							l.pop_front();
							break;
						}
						if (l.size() == 0) {
							h = false;
							break;
						}
					}
					if (l.size() == 0) {
						h = false;
						break;
					}
					a = 1;
				}
				else {
					while (b > 0) {
						if (l.back() <= b) {
							b -= l.back();
							ansb += l.back();
							a += l.back();
							l.pop_back();
						}
						else {
							a += l.back();
							ansb += l.back();
							l.pop_back();
							break;
						}
						if (l.size() == 0) {
							h = false;
							break;
						}
					}
					if (l.size() == 0) {
						h = false;
						break;
					}
					b = 1;
				}
			}
			cout << ans << " " << ansa << " " << ansb << endl;
			ans = 0;
			ansa = 0;
			ansb = 0;
			a = 1;
			b = 1;
		}
	}
	return 0;
}


/*Winners never quit && Quitters never win*/
#include <iostream>
#include <deque>
using namespace std;
int t, n, a = 1, b = 1, x, j, k;
int ans, ansa, ansb;
deque <int> l;
bool h;
int main() {
	cin >> t;
	while (t--) {
		cin >> n;
		if (n < 3) {
			if (n == 2) {
				cin >> x >> k;
				cout << n << " " << x << " " << k << endl;
			}
			else {
				cin >> x;
				cout << n << " " << x << " 0" << endl;
			}
		}
		else {
			for (int i = 0;i < n;i++) {
				cin >> x;
				l.push_back(x);
			}
			ansa += l[0];
			b += l[0];
			ans = 1;
			l.pop_front();
			h = true;
			while (h) {
				ans++;
				if (ans & 1) {
					while (a > 0) {
						if (l[j] <= a) {
							a -= l[j];
							ansa += l[j];
							b += l[j];
							l.pop_front();
						}
						else {
							b += l[j];
							ansa += l[j];
							l.pop_front();
							break;
						}
						if (l.size() == 0) {
							h = false;
							break;
						}
					}
					a = 1;
				}
				else {
					while (b > 0) {
						if (l.back() <= b) {
							b -= l.back();
							ansb += l.back();
							a += l.back();
							l.pop_back();
						}
						else {
							a += l.back();
							ansb += l.back();
							l.pop_back();
							break;
						}
						if (l.size() == 0) {
							h = false;
							break;
						}
					}
					b = 1;
				}
			}
			cout << ans << " " << ansa << " " << ansb << endl;
			ans = 0;
			ansa = 0;
			ansb = 0;
			a = 1;
			b = 1;
		}
	}
	return 0;
}


  #include <iostream>
    #include <bits/stdc++.h>
    #include <math.h>
    using namespace std;
    #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>

    #define ull unsigned long long
    #define int long long
    #define pb push_back
    #define SZ(x) ((int)x.size())
    #define mp make_pair
    #define ff first
    #define ss second
    #define lb lower_bound
    #define ub upper_bound
    #define endl "\n"
    #define Max(x,y,z) max(x,max(y,z))
    #define Min(x,y,z) min(x,min(y,z))
    #define MAX 1e18
    #define PI 3.14159265
    const int mod = 1e9 + 7;

    #define ordered_set tree<pair<int, int>, null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>

    int power(int x, int y)
    {
       int res = 1;

        while (y > 0)
        {

            if (y & 1)
                res = (long long)(res*x);

            y = y>>1;

            if (x<=100000000)
            x = (long long)(x*x);

            //cout<<x<<'\n';
        }
        return res;
    }

    int gcd (int a, int b) {
        if (b == 0)
            return a;
        else
            return gcd (b, a % b);
    }

    int ceiling(int a,int b){
      if(a%b!=0){
        return (a/b)+1;

      }
      else
        return (a/b);
    }

    int lcm (int a, int b) {
        return a / gcd(a, b) * b;
    }

    bool isPrime(int n)
    {
        // Corner cases
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0)
            return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }

void solve()
{
  int n;
  cin>>n;
  int c[n];
  for(int i=0;i<n;i++){
    cin>>c[i];
  }

  if(n==1){
    cout<<1<<" "<<c[0]<<" "<<0<<endl;
    return;
  }

  int a=0;
  int b=0;
  int l=0;
  int r=n-1;
  int moves=0;

  a+=c[0];
  l++;
  int prev=c[0];
  moves++;

  while(l<=r)
  {
    if(c[r]>prev and moves%2!=0){

      b+=c[r];
      prev=c[r];
      r--;
      moves++;

    }
    if(c[r]<=prev and moves%2!=0){
      int k=0;

      while(k<=prev and l<=r){
        k+=c[r];
        r--;

      }
      moves++;

      b+=k;
      prev=k;
    }

     if(c[l]>prev and moves%2==0){
      a+=c[l];
      prev=c[l];
      l++;
      moves++;

    }

    if(c[l]<=prev and moves%2==0){
      int j=0;

      while(j<=prev and l<=r){
        j+=c[l];
        l++;
      }

      a+=j;
      prev=j;
      moves++;
    }

  }

    cout<<moves<<" "<<a<<" "<<b<<endl;

  return;
}

 int32_t main()

{
   IOS;

   int t;
   cin>>t;
   while(t--){
    solve();
   }

   return 0;

}


  #include <iostream>
    #include <bits/stdc++.h>
    #include <math.h>
    using namespace std;
    #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>

    #define ull unsigned long long
    #define int long long
    #define pb push_back
    #define SZ(x) ((int)x.size())
    #define mp make_pair
    #define ff first
    #define ss second
    #define lb lower_bound
    #define ub upper_bound
    #define endl "\n"
    #define Max(x,y,z) max(x,max(y,z))
    #define Min(x,y,z) min(x,min(y,z))
    #define MAX 1e18
    #define PI 3.14159265
    const int mod = 1e9 + 7;

    #define ordered_set tree<pair<int, int>, null_type,less<pair<int, int>>, rb_tree_tag,tree_order_statistics_node_update>

    int power(int x, int y)
    {
       int res = 1;

        while (y > 0)
        {

            if (y & 1)
                res = (long long)(res*x);

            y = y>>1;

            if (x<=100000000)
            x = (long long)(x*x);

            //cout<<x<<'\n';
        }
        return res;
    }

    int gcd (int a, int b) {
        if (b == 0)
            return a;
        else
            return gcd (b, a % b);
    }

    int ceiling(int a,int b){
      if(a%b!=0){
        return (a/b)+1;

      }
      else
        return (a/b);
    }

    int lcm (int a, int b) {
        return a / gcd(a, b) * b;
    }

    bool isPrime(int n)
    {
        // Corner cases
        if (n <= 1)
            return false;
        if (n <= 3)
            return true;

        // This is checked so that we can skip
        // middle five numbers in below loop
        if (n % 2 == 0 || n % 3 == 0)
            return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }

void solve()
{
  int n;
  cin>>n;
  int c[n];
  for(int i=0;i<n;i++){
    cin>>c[i];
  }

  if(n==1){
    cout<<1<<" "<<c[0]<<" "<<0<<endl;
    return;
  }

  int a=0;
  int b=0;
  int l=0;
  int r=n-1;
  int moves=0;

  a+=c[0];
  l++;
  int prev=c[0];
  moves++;

  while(l<=r)
  {
    if(c[r]>prev and moves%2!=0){

      b+=c[r];
      prev=c[r];
      r--;

    }
    else if(c[r]<=prev and moves%2!=0){
      int k=0;

      while(k<=prev and l<=r){
        k+=c[r];
        r--;

      }

      b+=k;
      prev=k;
    }

    else if(c[l]>prev and moves%2==0){
      a+=c[l];
      prev=c[l];
      l++;

    }

    else if(c[l]<=prev and moves%2==0){
      int j=0;

      while(j<=prev and l<=r){
        j+=c[l];
        l++;
      }

      a+=j;
      prev=j;
    }
    moves++;

  }

    cout<<moves<<" "<<a<<" "<<b<<endl;

  return;
}

 int32_t main()

{
   IOS;

   int t;
   cin>>t;
   while(t--){
    solve();
   }

   return 0;

}