#include<bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC optimize("no-stack-protector")
// #define ll __int128
#define ll long long
// #define ll int
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
// #define mod 998244353
#define mp make_pair
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define ff first
#define ss second
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sc(a) scanf("%lld",&a)
#define pf printf
#define sz(a) (int)(a.size())
#define psf push_front
#define ppf pop_front
#define ppb pop_back
#define pb push_back
#define pq priority_queue
#define all(s) s.begin(),s.end()
#define sp(a) setprecision(a)
#define rz resize
#define ld long double
#define inf (ll)1e18
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define eb emplace_back
const double pi = acos(-1);
ll binpow(ll a, ll b){ll res=1;while(b!=0){if(b&1)res*=a;a*=a;b>>=1;}return res;}
// ll binpow(ll a, ll b, ll md){ll res=1;a%=mod;while(b!=0){if(b&1)res*=a,res%=md;a*=a,a%=md;b>>=1;}return res%md;}
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("xortransform.in","r",stdin);
// freopen("xortransform.out","w",stdout);
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
int z=1;
cin>>z;
f(i,1,z+1)
{
//cout<<"Case #"<<i<<": ";
ll n,K;
string s;
cin>>n>>K>>s;
vector<int> id;
f(i,0,sz(s))
{
if(s[i]=='1')
id.pb(i);
}
int len=sz(id);
vector<vector<ll> > dp(len,vector<ll> (3,inf));
if(sz(id)==0)
{
cout<<"0\n";
continue;
}
if(id[0]-1<0)
dp[0][0]=inf;
dp[0][1]=dp[0][2]=1;
f(i,1,len)
{
f(j,0,3)
{
ll deltar=j-1,nr=id[i]+deltar;
f(k,0,3)
{
ll deltal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wZW4oIm91dHB1dC50eHQiLCJ3IixzdGRvdXQpOwovLyAjZW5kaWYKICAgIGludCB6PTE7CiAgICBjaW4+Pno7CiAgICBmKGksMSx6KzEpCiAgICB7CiAgICAgICAgLy9jb3V0PDwiQ2FzZSAjIjw8aTw8IjogIjsKICAgICAgICBsbCBuLEs7CiAgICAgICAgc3RyaW5nIHM7CiAgICAgICAgY2luPj5uPj5LPj5zOwogICAgICAgIHZlY3RvcjxpbnQ+IGlkOwogICAgICAgIGYoaSwwLHN6KHMpKQogICAgICAgIHsKICAgICAgICAgICAgaWYoc1tpXT09JzEnKQogICAgICAgICAgICAgICAgaWQucGIoaSk7CiAgICAgICAgfQogICAgICAgIGludCBsZW49c3ooaWQpOwogICAgICAgIHZlY3Rvcjx2ZWN0b3I8bGw+ID4gZHAobGVuLHZlY3RvcjxsbD4gKDMsaW5mKSk7CiAgICAgICAgaWYoc3ooaWQpPT0wKQogICAgICAgIHsKICAgICAgICAgICAgY291dDw8IjBcbiI7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICBpZihpZFswXS0xPDApCiAgICAgICAgICAgIGRwWzBdWzBdPWluZjsKICAgICAgICBkcFswXVsxXT1kcFswXVsyXT0xOwogICAgICAgIGYoaSwxLGxlbikKICAgICAgICB7CiAgICAgICAgICAgIGYoaiwwLDMpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGxsIGRlbHRhcj1qLTEsbnI9aWRbaV0rZGVsdGFyOwogICAgICAgICAgICAgICAgZihrLDAsMykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBsbCBkZWx0YWw9ay0xLG5sPWlkW2ktMV0rZGVsdGFsOwogICAgICAgICAgICAgICAgICAgIGlmKGFicyhuci1ubCk8PUspCiAgICAgICAgICAgICAgICAgICAgICAgIGRwW2ldW2pdPW1pbihkcFtpXVtqXSxkcFtpLTFdW2tdKTsKICAgICAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICAgICAgICAgIGRwW2ldW2pdPW1pbihkcFtpXVtqXSwxK2RwW2ktMV1ba10pOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmKGlkW2xlbi0xXSsxPj1uKQogICAgICAgICAgICBkcFtsZW4tMV1bMl09aW5mOwogICAgICAgIGxsIGFucz1pbmY7CiAgICAgICAgZihqLDAsMykKICAgICAgICAgICAgYW5zPW1pbihhbnMsZHBbbGVuLTFdW2pdKTsKICAgICAgICBjb3V0PDxhbnM8PCJcbiI7CiAgICB9Cn0g