/*********************
*  Author: xuziyuan  *
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL t,n,x,ans,num0,num1,num[200020],mx,mn;
string s;

int main()
{
	cin>>t;
	rep(tn,t)
	{
		scanf("%lld%lld",&n,&x);
		cin>>s;
		num0=num1=ans=mx=mn=0;
		memset(num,0,sizeof(num));
		if(x==0) ans++;
		rep(i,n)
		{
			if(s[i]=='0') num0++;
			else num1++;
			num[num0-num1+100010]++;
			if(x==num0-num1) ans++;
			mx=max(mx,num0-num1);
			mn=min(mn,num0-num1);
		}
		//cout<<ans<<endl;
		LL val=num0-num1;
		if(val!=0)
		{
			LL lb=x-mx,ub=x-mn,bas;
			if(lb>=0&&val>0)
			{
				bas=(lb+val-1)/val*val;
				for(LL i=bas;lb<=i&&i<=ub;i+=val) ans+=num[x-i+100010];//,cout<<i<<' '<<ans<<endl;
			}
			if(ub<=0&&val<0)
			{
				bas=(-ub-val-1)/(-val)*(-val);
				for(LL i=bas;lb<=i&&i<=ub;i+=val) ans+=num[x-i+100010];
			}
			cout<<ans<<endl;
		}
		else puts("-1");
	}
	return 0;
}


/*********************
*  Author: xuziyuan  *
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL t,n,x,ans,num0,num1,num[100010];
string s;

int main()
{
	cin>>t;
	rep(tn,t)
	{
		scanf("%lld%lld",&n,&x);
		cin>>s;
		num0=num1=ans=0;
		if(x==0) ans++;
		LL res=0;
		rep(i,n)
		{
			if(s[i]=='0') num0++;
			else num1++;
			num[i]=num0-num1;
			if(x==num0-num1) res++;
		}
		LL val=num0-num1;
		if(val!=0)
		{
			rep(i,n) if((x-num[i])%val==0&&(x-num[i])/val>=0) ans++;
			cout<<ans<<endl;
		}
		else
		{
			if(res==0) cout<<0<<endl;
			else puts("-1");
		}
	}
	return 0;
}


/*********************
*  Author: xuziyuan  *
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL t,n,x,ans,num0,num1,num[400040],mx,mn;
string s;

int main()
{
	cin>>t;
	rep(tn,t)
	{
		scanf("%lld%lld",&n,&x);
		cin>>s;
		num0=num1=ans=0;
		mx=-1e18;
		mn=1e18;
		memset(num,0,sizeof(num));
		if(x==0) ans++;
		rep(i,n)
		{
			if(s[i]=='0') num0++;
			else num1++;
			num[num0-num1+200020]++;
			if(x==num0-num1) ans++;
			mx=max(mx,num0-num1);
			mn=min(mn,num0-num1);
		}
		LL val=num0-num1;
		if(val!=0)
		{
			LL lb=x-mx,ub=x-mn,bas;
			if(lb>0&&val>0)
			{
				bas=(lb+val-1)/val*val;
				if(bas==0) bas=val;
				for(LL i=bas;lb<=i&&i<=ub;i+=val) ans+=num[x-i+200020];
			}
			if(ub<0&&val<0)
			{
				bas=(-ub-val-1)/(-val)*val;
				if(bas==0) bas=val;
				//cout<<bas<<endl;
				for(LL i=bas;lb<=i&&i<=ub;i+=val) ans+=num[x-i+200020];
			}
			if(lb<=0&&0<=ub) for(LL i=val;lb<=i&&i<=ub;i+=val) ans+=num[x-i+200020];
			cout<<ans<<endl;
		}
		else
		{
			if(ans==0) cout<<0<<endl;
			else puts("-1");
		}
	}
	return 0;
}


/*********************
*  Author: xuziyuan  *
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL t,n,x,ans,num0,num1,num[400040],mx,mn;
string s;

int main()
{
	cin>>t;
	rep(tn,t)
	{
		scanf("%lld%lld",&n,&x);
		cin>>s;
		num0=num1=ans=0;
		mx=-1e18;
		mn=1e18;
		memset(num,0,sizeof(num));
		if(x==0) ans++;
		rep(i,n)
		{
			if(s[i]=='0') num0++;
			else num1++;
			num[num0-num1+200020]++;
			//if(x==num0-num1) ans++;
			mx=max(mx,num0-num1);
			mn=min(mn,num0-num1);
		}
		//cout<<ans<<endl;
		LL val=num0-num1;
		if(val!=0)
		{
			LL lb=x-mx,ub=x-mn,bas;
			if(lb>=0&&val>0)
			{
				bas=(lb+val-1)/val*val;
				for(LL i=bas;lb<=i&&i<=ub;i+=val) ans+=num[x-i+200020];//,cout<<i<<' '<<ans<<endl;
			}
			if(ub<=0&&val<0)
			{
				bas=(-ub-val-1)/(-val)*(-val);
				for(LL i=bas;lb<=i&&i<=ub;i+=val) ans+=num[x-i+200020];
			}
			if(lb<=0&&0<=ub) for(LL i=0;lb<=i&&i<=ub;i+=val) ans+=num[x-i+200020];
			cout<<ans<<endl;
		}
		else
		{
			if(ans==0) cout<<0<<endl;
			else puts("-1");
		}
	}
	return 0;
}


/*********************
*  Author: xuziyuan  *
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL t,n,x,ans,num0,num1,num[400040],mx,mn;
string s;

int main()
{
	cin>>t;
	rep(tn,t)
	{
		scanf("%lld%lld",&n,&x);
		cin>>s;
		num0=num1=ans=0;
		mx=-1e18;
		mn=1e18;
		memset(num,0,sizeof(num));
		if(x==0) ans++;
		rep(i,n)
		{
			if(s[i]=='0') num0++;
			else num1++;
			num[num0-num1+200020]++;
			if(x==num0-num1) ans++;
			mx=max(mx,num0-num1);
			mn=min(mn,num0-num1);
		}
		//cout<<ans<<endl;
		LL val=num0-num1;
		if(val!=0)
		{
			LL lb=x-mx,ub=x-mn,bas;
			if(lb>=0&&val>0)
			{
				bas=(lb+val-1)/val*val;
				for(LL i=bas;lb<=i&&i<=ub;i+=val) ans+=num[x-i+200020];//,cout<<i<<' '<<ans<<endl;
			}
			if(ub<=0&&val<0)
			{
				bas=(-ub-val-1)/(-val)*(-val);
				for(LL i=bas;lb<=i&&i<=ub;i+=val) ans+=num[x-i+200020];
			}
			if(lb<=0&&0<=ub) for(LL i=0;lb<=i&&i<=ub;i+=val) ans+=num[x-i+200020];
			cout<<ans<<endl;
		}
		else
		{
			if(ans==0) cout<<0<<endl;
			else puts("-1");
		}
	}
	return 0;
}


/*********************
*  Author: xuziyuan  *
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int t,n,x,ans,num0,num1,num[200020],mx,mn;
string s;

int main()
{
	cin>>t;
	rep(tn,t)
	{
		scanf("%d%d",&n,&x);
		cin>>s;
		num0=num1=ans=mx=mn=0;
		memset(num,0,sizeof(num));
		num[100010]++;
		if(x==0) ans++;
		rep(i,n)
		{
			if(s[i]=='0') num0++;
			else num1++;
			if(i!=n-1) num[num0-num1+100010]++;
			if(i!=n-1&&x==num0-num1) ans++;
			mx=max(mx,num0-num1);
			mn=min(mn,num0-num1);
		}
		//cout<<ans<<endl;
		int val=num0-num1;
		if(val!=0)
		{
			int lb=x-mx,ub=x-mn,bas;
			if(lb>=0&&val>0)
			{
				bas=(lb+val-1)/val*val;
				for(int i=bas;lb<=i&&i<=ub;i+=val) ans+=num[x-i+100010];//,cout<<i<<' '<<ans<<endl;
			}
			if(ub<=0&&val<0)
			{
				bas=(-ub-val-1)/(-val)*(-val);
				for(int i=bas;lb<=i&&i<=ub;i+=val) ans+=num[x-i+100010];
			}
			cout<<ans<<endl;
		}
		else puts("-1");
	}
	return 0;
}


/*********************
*  Author: xuziyuan  *
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

LL t,n,x,ans,num0,num1,num[400040],mx,mn;
string s;

int main()
{
	cin>>t;
	rep(tn,t)
	{
		scanf("%lld%lld",&n,&x);
		cin>>s;
		num0=num1=ans=0;
		mx=-1e18;
		mn=1e18;
		memset(num,0,sizeof(num));
		if(x==0) ans++;
		rep(i,n)
		{
			if(s[i]=='0') num0++;
			else num1++;
			num[num0-num1+200020]++;
			if(x==num0-num1) ans++;
			mx=max(mx,num0-num1);
			mn=min(mn,num0-num1);
		}
		//cout<<ans<<endl;
		LL val=num0-num1;
		if(val!=0)
		{
			LL lb=x-mx,ub=x-mn,bas;
			if(lb>=0&&val>0)
			{
				bas=(lb+val-1)/val*val;
				for(LL i=max(1LL,bas);lb<=i&&i<=ub;i+=val) ans+=num[x-i+200020];//,cout<<i<<' '<<ans<<endl;
			}
			if(ub<=0&&val<0)
			{
				bas=(-ub-val-1)/(-val)*(-val);
				for(LL i=max(1LL,bas);lb<=i&&i<=ub;i+=val) ans+=num[x-i+200020];
			}
			if(lb<=0&&0<=ub) for(LL i=1;lb<=i&&i<=ub;i+=val) ans+=num[x-i+200020];
			cout<<ans<<endl;
		}
		else
		{
			if(ans==0) cout<<0<<endl;
			else puts("-1");
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector < long long > vll;
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef vector < int > vi;

#define deb(x) cout << #x << " : " << x << endl
#define deb2(x , y) cout << #x << " : " << x << " , "<< #y << " : " << y << endl
#define deb3(x , y , z) cout << #x << " : " << x << " , " << #y << " : " << y << " , " << #z << " : " << z << endl
#define deb4(a , b , c , d) cout << #a << " : " << a << " , " << #b << " : " << b << " , " << #c << " : " << c << " , " << #d << " : " << d << endl
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,a,n) for(int i = a; i < n; i++)
#define rsz(x,n) x.clear(); x.resize(n)
#define rrsz(x,a,n) x.clear(); x.resize(n,a)
#define wt while(true)
#define all(x) x.begin(),x.end()
#define pb push_back
#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
#define s(n) cin >> n
#define ls(x) ((2*(x)) + 1)
#define rs(x) ((ls(x)) + 1)
#define md(a,b) ((b)+((a) - (b))/2)
#define INF (1e9 + 7)
#define endl '\n'

void solve(){
	ll n , x;
	cin >> n >> x;

	string s;
	cin >> s;

	ll zero = count(all(s) , '0');
	ll diff = zero - (n - zero);

	ll curr = 0;
	ll counter = 0;

	for(ll i = 0 ; i < n ; i++){
		if(diff == 0){
			if(curr == x){
				cout << -1 << endl;
				return;
			}
		} else if (abs(x - curr) % abs(diff) == 0LL){
			if((x-curr) / diff >= 0LL){
				counter++;
			}
		}

		if(s[i] == '0'){curr++;}
		else{curr--;}
	}

	cout << counter << endl;
}

int main(){
	csl;

	int testcase;
	cin >> testcase;
	//testcase = 1;

	for(int i = 0 ; i < testcase ; i++){
		solve();
	}

	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#define deb(x) cout << #x << " : " << x << endl
#define fr(x,n) for (int x = 0 ; x < n ; ++x)
#define Fr(x,k,n) for (int x = k ; x < n ; ++x)
#define pb push_back
typedef long long int ll ;
using namespace std;

ll pow(ll base , ll power , ll mod) {
    if (power == 0) return 1 ;
    else if (power % 2 == 0) return ((pow(base, power/2 , mod) % mod) * (pow(base , power/2 , mod) % mod ) )% mod;
    else return ((pow(base , power/2,mod) % mod) * (base % mod) * (pow(base,power/2,mod) % mod)) % mod;
}

void solve(int len , int x ,string input) {
    int count0 = 0 , count1 = 0 ;
    count0 = (int)count(input.begin() , input.end() , '0');
    count1 = len - count0;
    int diff = count0 - count1;
    int answer = 0;
    int cnt = 0;
    bool is_infinity = false;

    fr(i , len ){
        if (diff == 0 && cnt == x) {
            is_infinity = true;
            break;
        }
        else if (abs(x - cnt) % abs(diff) == 0) {
            if ((x-cnt) / diff >= 0) {
                answer++;
            }
        }
        if (input[i]-'0' == 0) cnt++;
        else cnt--;

    }
    if (is_infinity) answer = -1;
    cout << answer << endl;
}

int main() {
    int testcase ;
    cin >> testcase ;
    fr(i , testcase) {
        int len;
        cin >> len;
        int diff ;
        cin >> diff ;
        string input ;
        cin >> input ;
        solve(len , diff , input);
    }
    return 0;
}


#include<bits/stdc++.h>
#define deb(x) cout << #x << " : " << x << endl
#define fr(x,n) for (int x = 0 ; x < n ; ++x)
#define Fr(x,k,n) for (int x = k ; x < n ; ++x)
#define pb push_back
typedef long long int ll ;
using namespace std;

ll pow(ll base , ll power , ll mod) {
    if (power == 0) return 1 ;
    else if (power % 2 == 0) return ((pow(base, power/2 , mod) % mod) * (pow(base , power/2 , mod) % mod ) )% mod;
    else return ((pow(base , power/2,mod) % mod) * (base % mod) * (pow(base,power/2,mod) % mod)) % mod;
}

void solve(int len , int x ,string input) {
    int count0 = 0;
    count0 = (int)count(input.begin() , input.end() , '0');
    int diff = count0 - (len - count0);
    int answer = 0;
    int cnt = 0;
    bool is_infinity = false;

    fr(i , len ){
        if (diff == 0 && cnt == x) {
            is_infinity = true;
            break;
        }
        else if (abs(x - cnt) % abs(diff) == 0) {
            if ((x-cnt) / diff >= 0) {
                answer++;
            }
        }
        if (input[i]-'0' == 0) cnt++;
        else cnt--;

    }
    if (is_infinity) answer = -1;
    cout << answer << endl;
}

int main() {

    ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);

    int testcase ;
    cin >> testcase ;
    fr(i , testcase) {
        int len;
        cin >> len;
        int diff ;
        cin >> diff ;
        string input ;
        cin >> input ;
        solve(len , diff , input);
    }
    return 0;
}


#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#define deb(x) cout << #x << " : " << x << endl
#define fr(x,n) for (int x = 0 ; x < n ; ++x)
#define Fr(x,k,n) for (int x = k ; x < n ; ++x)
#define pb push_back
typedef long long int ll ;
using namespace std;

ll pow(ll base , ll power , ll mod) {
    if (power == 0) return 1 ;
    else if (power % 2 == 0) return ((pow(base, power/2 , mod) % mod) * (pow(base , power/2 , mod) % mod ) )% mod;
    else return ((pow(base , power/2,mod) % mod) * (base % mod) * (pow(base,power/2,mod) % mod)) % mod;
}

void solve(ll len , ll x ,string input) {
    ll count0 = 0;
    count0 = (ll)count(input.begin() , input.end() , '0');
    ll diff = count0 - (len - count0);
    ll answer = 0;
    ll cnt = 0;
    bool is_infinity = false;

    fr(i , len ){
        if (diff == 0 && cnt == x) {
            is_infinity = true;
            break;
        }
        else if ((x - cnt)*(diff) >= 0) {
            if ((x-cnt) >= 0 && (x-cnt) % diff == 0) answer++;
            else if ((x-cnt) < 0 && (cnt-x) % (-1*diff) == 0 ) answer++;
        }
        if (input[i]-'0' == 0) cnt++;
        else cnt--;

    }
    if (is_infinity) answer = -1;
    cout << answer << endl;
}

int main() {
    ll testcase ;
    cin >> testcase ;
    fr(i , testcase) {
        ll len;
        cin >> len;
        ll diff ;
        cin >> diff ;
        string input ;
        cin >> input ;
        solve(len , diff , input);
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#define deb(x) cout << #x << " : " << x << endl
#define fr(x,n) for (int x = 0 ; x < n ; ++x)
#define Fr(x,k,n) for (int x = k ; x < n ; ++x)
#define pb push_back
typedef long long int ll ;
using namespace std;

ll pow(ll base , ll power , ll mod) {
    if (power == 0) return 1 ;
    else if (power % 2 == 0) return ((pow(base, power/2 , mod) % mod) * (pow(base , power/2 , mod) % mod ) )% mod;
    else return ((pow(base , power/2,mod) % mod) * (base % mod) * (pow(base,power/2,mod) % mod)) % mod;
}

inline void solve(int len , int x ,string input) {
    int count0 = 0;
    count0 = (int)count(input.begin() , input.end() , '0');
    int diff = count0 - (len - count0);
    int answer = 0;
    int cnt = 0;
    bool is_infinity = false;

    fr(i , len ){
        if (diff == 0 && cnt == x) {
            is_infinity = true;
            break;
        }
        else if (abs(x - cnt) % abs(diff) == 0) {
            if ((x-cnt) / diff >= 0) {
                answer++;
            }
        }
        if (input[i]-'0' == 0) cnt++;
        else cnt--;

    }
    if (is_infinity) answer = -1;
    cout << answer << endl;
}

int main() {
    int testcase ;
    cin >> testcase ;
    fr(i , testcase) {
        int len;
        cin >> len;
        int diff ;
        cin >> diff ;
        string input ;
        cin >> input ;
        solve(len , diff , input);
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#define deb(x) cout << #x << " : " << x << endl
#define fr(x,n) for (int x = 0 ; x < n ; ++x)
#define Fr(x,k,n) for (int x = k ; x < n ; ++x)
#define pb push_back
typedef long long int ll ;
using namespace std;

ll pow(ll base , ll power , ll mod) {
    if (power == 0) return 1 ;
    else if (power % 2 == 0) return ((pow(base, power/2 , mod) % mod) * (pow(base , power/2 , mod) % mod ) )% mod;
    else return ((pow(base , power/2,mod) % mod) * (base % mod) * (pow(base,power/2,mod) % mod)) % mod;
}

void solve(int len , int x ,string input) {
    int count0 = 0;
    count0 = (int)count(input.begin() , input.end() , '0');
    int diff = count0 - (len - count0);
    int answer = 0;
    int cnt = 0;
    bool is_infinity = false;

    fr(i , len ){
        if (diff == 0 && cnt == x) {
            is_infinity = true;
            break;
        }
        else if (abs(x - cnt) % abs(diff) == 0) {
            if ((x-cnt) / diff >= 0) {
                answer++;
            }
        }
        if (input[i]-'0' == 0) cnt++;
        else cnt--;

    }
    if (is_infinity) answer = -1;
    cout << answer << endl;
}

int main() {
    int testcase ;
    cin >> testcase ;
    fr(i , testcase) {
        int len;
        cin >> len;
        int diff ;
        cin >> diff ;
        string input ;
        cin >> input ;
        solve(len , diff , input);
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#define deb(x) cout << #x << " : " << x << endl
#define fr(x,n) for (int x = 0 ; x < n ; ++x)
#define Fr(x,k,n) for (int x = k ; x < n ; ++x)
#define pb push_back
typedef long long int ll ;
using namespace std;

ll pow(ll base , ll power , ll mod) {
    if (power == 0) return 1 ;
    else if (power % 2 == 0) return ((pow(base, power/2 , mod) % mod) * (pow(base , power/2 , mod) % mod ) )% mod;
    else return ((pow(base , power/2,mod) % mod) * (base % mod) * (pow(base,power/2,mod) % mod)) % mod;
}
//check
void solve(int len , int x ,string input) {
    int count0 = 0 , count1 = 1-1;
    for (char c : input) {
        if (c-'0' == 0) {
            count0++;
        }
    }
    count1 = len - count0;
    int diff = count0 - count1;
    int answer = 0;
    int cnt = 0;
    bool is_infinity = false;

    fr(i , len ){
        if (input[i]-'0' == 0) cnt++;
        else cnt--;

        if (diff == 0 && cnt == x) {
            is_infinity = true;
            break;
        }
        else if (abs(x - cnt) % abs(diff) == 0) {
            if ((x-cnt) / diff >= 0) {
                answer++;
            }
        }
    }
    if (is_infinity) answer = -1;
    cout << answer << endl;
}

int main() {
    int testcase ;
    cin >> testcase ;
    fr(i , testcase) {
        int len;
        cin >> len;
        int diff ;
        cin >> diff ;
        string input ;
        cin >> input ;
        solve(len , diff , input);
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#define deb(x) cout << #x << " : " << x << endl
#define fr(x,n) for (int x = 0 ; x < n ; ++x)
#define Fr(x,k,n) for (int x = k ; x < n ; ++x)
#define pb push_back
typedef long long int ll ;
using namespace std;

ll pow(ll base , ll power , ll mod) {
    if (power == 0) return 1 ;
    else if (power % 2 == 0) return ((pow(base, power/2 , mod) % mod) * (pow(base , power/2 , mod) % mod ) )% mod;
    else return ((pow(base , power/2,mod) % mod) * (base % mod) * (pow(base,power/2,mod) % mod)) % mod;
}

void solve(int len , int x ,string input) {
    int count0 = 0 , count1 = 0 ;
    for (char c : input) {
        if (c-'0' == 0) {
            count0++;
        }
    }
    count1 = len - count0;
    int diff = count0 - count1;
    int answer = 0;
    int cnt = 0;
    bool is_infinity = false;

    fr(i , len ){
        if (input[i]-'0' == 0) cnt++;
        else cnt--;

        if (diff == 0 && cnt == x) {
            is_infinity = true;
            break;
        }
        else if ((abs(x - cnt) % abs(diff)) == 0) {
            if ((x-cnt) / diff >= 0) {
                answer++;
            }
        }
    }
    if (is_infinity) answer = -1;
    cout << answer << endl;
}

int main() {
    int testcase ;
    cin >> testcase ;
    fr(i , testcase) {
        int len;
        cin >> len;
        int diff ;
        cin >> diff ;
        string input ;
        cin >> input ;
        solve(len , diff , input);
    }
    return 0;
}


#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#define deb(x) cout << #x << " : " << x << endl
#define fr(x,n) for (int x = 0 ; x < n ; ++x)
#define Fr(x,k,n) for (int x = k ; x < n ; ++x)
#define pb push_back
typedef long long int ll ;
using namespace std;

ll pow(ll base , ll power , ll mod) {
    if (power == 0) return 1 ;
    else if (power % 2 == 0) return ((pow(base, power/2 , mod) % mod) * (pow(base , power/2 , mod) % mod ) )% mod;
    else return ((pow(base , power/2,mod) % mod) * (base % mod) * (pow(base,power/2,mod) % mod)) % mod;
}

void solve(ll len , ll x ,string input) {
    ll count0 = 0;
    count0 = (ll)count(input.begin() , input.end() , '0');
    ll diff = count0 - (len - count0);
    ll answer = 0;
    ll cnt = 0;
    bool is_infinity = false;

    fr(i , len ){
        if (diff == 0) {
            if (cnt == x) {
                is_infinity = true;
                break;
            }
        }
        else if ((x - cnt)*(diff) >= 0) {
            if ((x-cnt) >= 0 && (x-cnt) % diff == 0) answer++;
            else if ((x-cnt) < 0 && (cnt-x) % (-1*diff) == 0 ) answer++;
        }
        if (input[i]-'0' == 0) cnt++;
        else cnt--;

    }
    if (is_infinity) answer = -1;
    cout << answer << endl;
}

int main() {
    ll testcase ;
    cin >> testcase ;
    fr(i , testcase) {
        ll len;
        cin >> len;
        ll diff ;
        cin >> diff ;
        string input ;
        cin >> input ;
        solve(len , diff , input);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector < long long > vll;
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef vector < int > vi;

#define deb(x) cout << #x << " : " << x << endl
#define deb2(x , y) cout << #x << " : " << x << " , "<< #y << " : " << y << endl
#define deb3(x , y , z) cout << #x << " : " << x << " , " << #y << " : " << y << " , " << #z << " : " << z << endl
#define deb4(a , b , c , d) cout << #a << " : " << a << " , " << #b << " : " << b << " , " << #c << " : " << c << " , " << #d << " : " << d << endl
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,a,n) for(int i = a; i < n; i++)
#define rsz(x,n) x.clear(); x.resize(n)
#define rrsz(x,a,n) x.clear(); x.resize(n,a)
#define wt while(true)
#define all(x) x.begin(),x.end()
#define pb push_back
#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
#define s(n) cin >> n
#define ls(x) ((2*(x)) + 1)
#define rs(x) ((ls(x)) + 1)
#define md(a,b) ((b)+((a) - (b))/2)
#define INF (1e9 + 7)
#define endl '\n'

void solve(){
	int n , x;
	cin >> n >> x;

	string s;
	cin >> s;

	int zero = count(all(s) , '0');
	int diff = zero - (n - zero);

	int curr = 0;
	int counter = 0;

	for(int i = 0 ; i < n ; i++){
		if(diff == 0 && curr == x){
			cout << -1 << endl;
			return;
		} else if (abs(x - curr) % abs(diff) == 0){
			if((x-curr) / diff >= 0){
				counter++;
			}
		}

		if(s[i] == '1'){curr++;}
		else{curr--;}
	}

	cout << counter << endl;
}

int main(){
    csl;

    int testcase;
    cin >> testcase;
	//testcase = 1;

	for(int i = 0 ; i < testcase ; i++){
		solve();
	}

    return 0;
}


#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#define deb(x) cout << #x << " : " << x << endl
#define fr(x,n) for (int x = 0 ; x < n ; ++x)
#define Fr(x,k,n) for (int x = k ; x < n ; ++x)
#define pb push_back
typedef long long int ll ;
using namespace std;

ll pow(ll base , ll power , ll mod) {
    if (power == 0) return 1 ;
    else if (power % 2 == 0) return ((pow(base, power/2 , mod) % mod) * (pow(base , power/2 , mod) % mod ) )% mod;
    else return ((pow(base , power/2,mod) % mod) * (base % mod) * (pow(base,power/2,mod) % mod)) % mod;
}

void solve(int len , int x ,string input) {
    int count0 = 0;
    count0 = (int)count(input.begin() , input.end() , '0');
    int diff = count0 - (len - count0);
    int answer = 0;
    int cnt = 0;
    bool is_infinity = false;

    fr(i , len ){
        if (diff == 0 && cnt == x) {
            is_infinity = true;
            break;
        }
        else if ((x - cnt)*(diff) >= 0) {
            if ((x-cnt) >= 0 && (x-cnt) % diff == 0) answer++;
            else if ((x-cnt) < 0 && (cnt-x) % (-1*diff) == 0 ) answer++;
        }
        if (input[i]-'0' == 0) cnt++;
        else cnt--;

    }
    if (is_infinity) answer = -1;
    cout << answer << endl;
}

int main() {
    int testcase ;
    cin >> testcase ;
    fr(i , testcase) {
        int len;
        cin >> len;
        int diff ;
        cin >> diff ;
        string input ;
        cin >> input ;
        solve(len , diff , input);
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#define deb(x) cout << #x << " : " << x << endl
#define fr(x,n) for (int x = 0 ; x < n ; ++x)
#define Fr(x,k,n) for (int x = k ; x < n ; ++x)
#define pb push_back
typedef long long int ll ;
using namespace std;

ll pow(ll base , ll power , ll mod) {
    if (power == 0) return 1 ;
    else if (power % 2 == 0) return ((pow(base, power/2 , mod) % mod) * (pow(base , power/2 , mod) % mod ) )% mod;
    else return ((pow(base , power/2,mod) % mod) * (base % mod) * (pow(base,power/2,mod) % mod)) % mod;
}

void solve(int len , int x ,string input) {
    int count0 = 0;
    count0 = (int)count(input.begin() , input.end() , '0');
    int diff = count0 - (len - count0);
    int answer = 0;
    int cnt = 0;
    bool is_infinity = false;

    fr(i , len ){
        if (diff == 0 && cnt == x) {
            is_infinity = true;
            break;
        }
        else if (abs(x - cnt) % abs(diff) == 0) {
            if ((x-cnt) / diff >= 0) {
                answer++;
            }
        }
        if (input[i]-'0' == 0) cnt++;
        else cnt--;

    }
    if (is_infinity) answer = -1;
    cout << answer << endl;
}

int main() {

    ios_base::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cout << fixed << setprecision(15);

    int testcase ;
    cin >> testcase ;
    fr(i , testcase) {
        int len;
        cin >> len;
        int diff ;
        cin >> diff ;
        string input ;
        cin >> input ;
        solve(len , diff , input);
    }
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#define deb(x) cout << #x << " : " << x << endl
#define fr(x,n) for (int x = 0 ; x < n ; ++x)
#define Fr(x,k,n) for (int x = k ; x < n ; ++x)
#define pb push_back
typedef long long int ll ;
using namespace std;

ll pow(ll base , ll power , ll mod) {
    if (power == 0) return 1 ;
    else if (power % 2 == 0) return ((pow(base, power/2 , mod) % mod) * (pow(base , power/2 , mod) % mod ) )% mod;
    else return ((pow(base , power/2,mod) % mod) * (base % mod) * (pow(base,power/2,mod) % mod)) % mod;
}

void solve(int len , int x ,string input) {
    int count0 = 0 , count1 = 0 ;
    for (char c : input) {
        if (c-'0' == 0) {
            count0++;
        }
    }
    count1 = len - count0;
    int diff = count0 - count1;
    int answer = 0;
    int cnt = 0;
    bool is_infinity = false;

    fr(i , len ){
        if (input[i]-'0' == 0) cnt++;
        else cnt--;

        if (diff == 0 && cnt == x) {
            is_infinity = true;
            break;
        }
        else if (abs(x - cnt) % abs(diff) == 0) {
            if ((x-cnt) / diff >= 0) {
                answer++;
            }
        }
    }
    if (is_infinity) answer = -1;
    cout << answer << endl;
}

int main() {
    int testcase ;
    cin >> testcase ;
    fr(i , testcase) {
        int len;
        cin >> len;
        int diff ;
        cin >> diff ;
        string input ;
        cin >> input ;
        solve(len , diff , input);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
string a,b  ;
vector<pair<char , int > > vec;
int pos ;
void solve(){
pos=0 ;
vec.clear() ;
int fin =1 ;
cin>>a>>b ;
for(int i=0;i<a.size();++i)
    vec.push_back(make_pair(a[i],i));
sort(vec.begin(),vec.end());
bool check =false;
for(int i=0;i<b.size();++i){
 auto it = lower_bound(vec.begin(),vec.end(),make_pair(b[i],pos)) ;
 if(lower_bound(vec.begin(),vec.end(),make_pair(b[i],0))==vec.end()){
    cout<<"-1\n" ;
    return ;
 }
 if(it!=vec.end()){
    if(it->second>pos){
     pos=max(pos,it->second) ;
     continue ;
    }
    else{
     it++ ;
     if(it!=vec.end())
        pos=max(pos,it->second);
        else {fin+=2 ;pos=0;}
    }
 }else{ fin+=2 ;
     pos =0 ;
     }

}
cout<<fin<<endl;
}
int main() {
    #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin) ;
  #endif
int t ; cin>>t ;
while(t--){
        solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1 ,sum;
string s ;
void solve(){
bool check =false ;
fin =0,sum=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
 if(s[i]=='0')sum++ ;
 else sum-- ;
}
int a =0;
for(int i=0;i<n;++i){
 if(!sum&&a==x){
    cout<<-1<<endl ;
    return ;
 }
 if(sum){
 if((x-a)%sum==0&&(x-a)/sum>=0)
        fin++;

}
if(s[i]=='0')a++ ;
else a-- ;
}
cout<<fin<<endl ;
}
int main() {
    #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin) ;
  #endif
int t ; cin>>t ;
while(t--){
        solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1 ,sum;
string s ;
void solve(){
bool check =false ;
int fin =0,suma=0,sumb=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
 if(s[i]=='0')suma++ ;
 else sumb++ ;
}
int a =0,b=0;
for(int i=0;i<n;++i){
 if(suma-sumb==0&&a-b==x){
    cout<<-1<<endl ;
    return ;
 }
 if(suma-sumb){
    int temp =suma-sumb;
 if((x-a+b)%temp==0&&(x-a+b)/temp>=0)
        fin++;

}
if(s[i]=='0')a++ ;
else b++ ;
}
cout<<fin<<endl ;
}
int main() {
    #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin) ;
  #endif
int t ; cin>>t ;
while(t--){
        solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}

if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
int dif =(c0-c1) ;
 if(dif==0)temp=1 ;
 else
 temp=(x+abs(dif)-1)/(dif) ;
 //if(x%(c0-c1)!=0)temp++;
 if(temp<0){
    cout<<fin<<endl ;
    return ;}
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
//cout<<temp<<endl ;
while(!sk.empty()){
    if(t0-t1==x&&temp>1)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
    if(c0-c1==x&&temp>1)fin++ ;
    sk2.pop() ;
}
cout<<fin<<endl ;
}
int main() {
 // freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}

if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
int dif =(c0-c1) ;
 if(dif==0)temp=1 ;
 else
 temp=(x+abs(dif)-1)/(dif) ;
 //if(x%(c0-c1)!=0)temp++;
 if(temp<0){
    cout<<fin<<endl ;
    return ;}
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
//cout<<temp<<endl ;
while(!sk.empty()){
    if(t0-t1==x&&temp>1)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
    if(c0-c1==x&&temp>1)fin++ ;
    sk2.pop() ;
}
cout<<fin<<endl ;
}
int main() {
  freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}

//if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
int dif =(c0-c1) ;
 if(dif==0)temp=1 ;
 else
 temp=(x+abs(dif)-1)/(dif) ;
 //if(x%(c0-c1)!=0)temp++;
 if(temp<0){
    cout<<fin<<endl ;
    return ;}
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
//cout<<temp<<endl ;
while(!sk.empty()){
    if(t0-t1==x&&temp>1)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
    if(c0-c1==x&&temp>1)fin++ ;
    sk2.pop() ;
}
cout<<fin<<endl ;
}
int main() {
  freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1 ,sum;
string s ;
void solve(){
bool check =false ;
int fin =0,suma=0,sumb=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
 if(s[i]=='0')suma++ ;
 else sumb++ ;
}
int a =0,b=0;
for(int i=0;i<n;++i){
 if(suma-sumb==0&&a==x){
    cout<<-1<<endl ;
    return ;
 }
 if(suma-sumb){
    int temp =suma-sumb;
 if((x-a+b)%temp==0&&(x-a+b)/temp>=0)
        fin++;

}
if(s[i]=='0')a++ ;
else b++ ;
}
cout<<fin<<endl ;
}
int main() {
    #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin) ;
  #endif
int t ; cin>>t ;
while(t--){
        solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}

//if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
int dif =(c0-c1) ;
 if(dif==0)temp=1 ;
 else
 temp=(x+abs(dif)-1)/(dif) ;
 //if(x%(c0-c1)!=0)temp++;
 if(temp<0){
    cout<<fin<<endl ;
    return ;}
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
//cout<<temp<<endl ;
while(!sk.empty()){
    if(t0-t1==x&&temp>1)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
    if(c0-c1==x&&temp>1)fin++ ;
    sk2.pop() ;
}
cout<<fin<<endl ;
}
int main() {
 // freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}

if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
int dif =(c0-c1) ;
 if(dif!=0){
 temp=(x+abs(dif)-1)/(dif) ;
 //if(x%(c0-c1)!=0)temp++;
  /*if(temp<0){
    cout<<fin<<endl ;
    return ;}*/
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
//cout<<temp<<endl ;
while(!sk.empty()){
    if(t0-t1==x&&temp>1)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
 if(c0-c1==x&&temp>1)fin++ ;
    sk2.pop() ;
}

 }
cout<<fin<<endl ;
}
int main() {
    #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin) ;
  #endif
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}

if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
int dif =(c0-c1) ;
 if(dif==0)temp=1 ;
 else
 temp=(x+abs(dif)-1)/(dif) ;
 //if(x%(c0-c1)!=0)temp++;
 /*if(temp<0){
    cout<<fin+1<<endl ;
    return ;}*/
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
//cout<<temp<<endl ;
while(!sk.empty()){
    if(t0-t1==x&&temp>0)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
 if(c0-c1==x&&temp>0)fin++ ;
    sk2.pop() ;
}
cout<<fin<<endl ;
}
int main() {
  //freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
if(x==0)fin++ ;
for(int i=0;i<n;++i){
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
if(c0-c1==x&&i!=n-1)fin++ ;//cout<<i<<"\t"<<c0-c1<<endl ;
}
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
if(c0-c1==0&&fin>0){
   cout<<-1<<"\n";
   return ;
 }
int dif =(c0-c1) ;
int temp=(x+abs(dif)-1)/(dif) ;
temp=abs(temp);
//cout<<fin<<endl;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
while(!sk.empty()){
    if(t0-t1==x&&temp>1)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
 if(c0-c1==x)fin++ ;
    sk2.pop() ;
}

cout<<fin<<endl ;
}
int main() {
    #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin) ;
  #endif
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1 ,sum;
string s ;
void solve(){
bool check =false ;
fin =0,sum=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
 if(s[i]=='0')sum++ ;
 else sum-- ;
}
int a =0 ,b=0;
for(int i=0;i<n;++i){
 if(!sum&&a==x){
    cout<<-1<<endl ;
    return ;
 }
 if(sum){
 if((x-b+a)%sum==0&&(x-b+a)/sum>=0)
        fin++;

}
if(s[i]=='0')a++ ;
else b++ ;
}
cout<<fin<<endl ;
}
int main() {
    #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin) ;
  #endif
int t ; cin>>t ;
while(t--){
        solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}

if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
int dif =(c0-c1) ;
 if(dif==0)temp=1 ;
 else
 temp=(x+abs(dif)-1)/(dif) ;
 //if(x%(c0-c1)!=0)temp++;
 /*if(temp<0){
    cout<<fin+1<<endl ;
    return ;}*/
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
//cout<<temp<<endl ;
while(!sk.empty()){
    if(t0-t1==x&&temp>1)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
 if(c0-c1==x&&temp>1)fin++ ;
    sk2.pop() ;
}
cout<<fin<<endl ;
}
int main() {
  //freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}

if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
int dif =(c0-c1) ;

 temp=(x+abs(dif)-1)/(dif) ;
 //if(x%(c0-c1)!=0)temp++;
 /*if(temp<0){
    cout<<fin+1<<endl ;
    return ;}*/
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
//cout<<temp<<endl ;
while(!sk.empty()){
    if(t0-t1==x&&temp>0)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
 if(c0-c1==x&&temp>0)fin++ ;
    sk2.pop() ;
}
cout<<fin<<endl ;
}
int main() {
 //freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}
//if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
 if(x==0)temp=1 ;
 else
 temp=x/((c0-c1)) ;
 if(x%(c0-c1)!=0)temp++;
 if(temp<0){
    cout<<fin<<endl ;
    return ;}
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
while(!sk.empty()){
    if(t0-t1==x)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
    if(c0-c1==x)fin++ ;
    sk2.pop() ;
}
cout<<fin<<endl ;
}
int main() {
 // freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}

if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
int dif =(c0-c1) ;
 if(dif!=0){
 temp=(x+abs(dif)-1)/(dif) ;
 //if(x%(c0-c1)!=0)temp++;
  /*if(temp<0){
    cout<<fin<<endl ;
    return ;}*/
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
//cout<<temp<<endl ;
while(!sk.empty()){
    if(t0-t1==x&&temp>1)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
 if(c0-c1==x&&temp>1)fin++ ;
    sk2.pop() ;
}

 }
cout<<fin<<endl ;
}
int main() {
  freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
if(x==0)fin++ ;
for(int i=0;i<n;++i){
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
if(c0-c1==x&&i!=n-1)fin++ ;//cout<<i<<"\t"<<c0-c1<<endl ;
}
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
if(c0-c1==0){
    if(fin>0){
   cout<<-1<<"\n";
   return ;}else cout<<0<<endl ;
   return ;
 }
int dif =(c0-c1) ;
int temp=(x+abs(dif)-1)/(dif) ;
temp=abs(temp);
//cout<<fin<<endl;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
while(!sk.empty()){
    if(t0-t1==x&&temp>1)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
 if(c0-c1==x)fin++ ;
    sk2.pop() ;
}
if(temp==1)fin++;
cout<<fin<<endl ;
}
int main() {
    #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin) ;
  #endif
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}

if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
int dif =(c0-c1) ;
 if(dif==0)temp=1 ;
 else
 temp=(x+abs(dif)-1)/(dif) ;
 //if(x%(c0-c1)!=0)temp++;
 /*if(temp<0){
    cout<<fin+1<<endl ;
    return ;}*/
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
//cout<<temp<<endl ;
while(!sk.empty()){
    if(t0-t1==x&&temp>1)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
 if(c0-c1==x&&temp>1)fin++ ;
    sk2.pop() ;
}
cout<<fin<<endl ;
}
int main() {
  freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
if(x==0)fin++ ;
for(int i=0;i<n;++i){
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
if(c0-c1==x&&i!=n-1)fin++ ;//cout<<i<<"\t"<<c0-c1<<endl ;
}
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
if(c0-c1==0){
    if(fin>0){
   cout<<-1<<"\n";
   return ;}else cout<<0<<endl ;
   return ;
 }
int dif =(c0-c1) ;
int temp=(x+abs(dif)-1)/(dif) ;
temp=abs(temp);
//cout<<fin<<endl;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
while(!sk.empty()){
    if(t0-t1==x&&temp>1)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
 if(c0-c1==x)fin++ ;
    sk2.pop() ;
}

cout<<fin<<endl ;
}
int main() {
    #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin) ;
  #endif
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
//if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}
//if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
int dif =(c0-c1) ;
 if(dif==0)temp=1 ;
 else
 temp=(x+abs(dif)-1)/(dif) ;
 //if(x%(c0-c1)!=0)temp++;
 if(temp<0){
    cout<<fin<<endl ;
    return ;}
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
while(!sk.empty()){
    if(t0-t1==x)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
    if(c0-c1==x)fin++ ;
    sk2.pop() ;
}
cout<<fin<<endl ;
}
int main() {
  //freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
//if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}
//if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
 if(c0-c1==0)temp=1 ;
 else
 temp=x/((c0-c1)) ;
 if(x%(c0-c1)!=0)temp++;
 if(temp<0){
    cout<<fin<<endl ;
    return ;}
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
while(!sk.empty()){
    if(t0-t1==x)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
    if(c0-c1==x)fin++ ;
    sk2.pop() ;
}
cout<<fin<<endl ;
}
int main() {
  //freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}

if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
int dif =(c0-c1) ;
 if(dif==0)temp=0 ;
 else
 temp=(x+abs(dif)-1)/(dif) ;
 //if(x%(c0-c1)!=0)temp++;
  if(temp<0){
    cout<<fin<<endl ;
    return ;}
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
//cout<<temp<<endl ;
while(!sk.empty()){
    if(t0-t1==x&&temp>0)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
 if(c0-c1==x)fin++ ;
    sk2.pop() ;
}
cout<<fin<<endl ;
}
int main() {
 // freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}

if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
int dif =(c0-c1) ;
 if(dif==0)temp=0 ;
 else
 temp=(x+abs(dif)-1)/(dif) ;
 //if(x%(c0-c1)!=0)temp++;
  if(temp<0){
    cout<<fin<<endl ;
    return ;}
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
//cout<<temp<<endl ;
while(!sk.empty()){
    if(t0-t1==x&&temp>0)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
 if(c0-c1==x)fin++ ;
    sk2.pop() ;
}
cout<<fin<<endl ;
}
int main() {
  freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int fin ,n ,x, c0,c1 ,sum;
string s ;
void solve(){
bool check =false ;
int fin =0,suma=0,sumb=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
 if(s[i]=='0')suma++ ;
 else sumb++ ;
}
int a =0,b=0;
for(int i=0;i<n;++i){
 if(suma-sumb==0&&a-b==x){
    cout<<-1<<endl ;
    return ;
 }
 if(suma-sumb){
    int temp =suma-sumb;
 if((x-a+b)%temp==0&&(x-a+b)/temp>=0)
        fin++;

}
if(s[i]=='0')a++ ;
else b++ ;
}
cout<<fin<<endl ;
}
int main() {
    #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin) ;
  #endif
int t ; cin>>t ;
while(t--){
        solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1;
stack<char >sk ;
stack<char>sk2 ;
string s ;
void solve(){
fin =0,c0=0,c1=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
if(c0-c1==x)fin++ ;
 if(s[i]=='0')c0++ ;
 else c1++ ;
 sk.push(s[i]);
}

if(c0-c1==x)fin++ ;
if(c0-c1==x){
    cout<<-1<<"\n" ;
    return ;
}
int temp ;
int dif =(c0-c1) ;

 temp=(x+abs(dif)-1)/(dif) ;
 //if(x%(c0-c1)!=0)temp++;
 /*if(temp<0){
    cout<<fin+1<<endl ;
    return ;}*/
   // cout<<temp<<endl ;
c0*=temp ;c1*=temp ;
int t0 =c0 ,t1 =c1 ;
//cout<<temp<<endl ;
while(!sk.empty()){
    if(t0-t1==x&&temp>0)fin++ ;
    if(sk.top()=='1')t1-- ;
    else t0--;
    sk2.push(sk.top()) ;
    sk.pop() ;
}
while(!sk2.empty()){
    if(sk2.top()=='1')c1++ ;
    else c0++;
 if(c0-c1==x&&temp>0)fin++ ;
    sk2.pop() ;
}
cout<<fin<<endl ;
}
int main() {
 freopen("in.txt","r",stdin) ;
int t ; cin>>t ;
while(t--){
    while(!sk.empty())sk.pop() ;
    while(!sk2.empty())sk2.pop() ;
    solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1 ,sum;
string s ;
void solve(){
bool check =false ;
int fin =0,suma=0,sumb=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
 if(s[i]=='0')suma++ ;
 else sumb++ ;
}
int a =0,b=0;
for(int i=0;i<n;++i){
 if(suma-sumb==0&&a==x){
    cout<<-1<<endl ;
    return ;
 }
 if(suma-sumb){
    int temp =suma-sumb;
 if((x-b+a)%temp==0&&(x-b+a)/temp>=0)
        fin++;

}
if(s[i]=='0')a++ ;
else b++ ;
}
cout<<fin<<endl ;
}
int main() {
    #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin) ;
  #endif
int t ; cin>>t ;
while(t--){
        solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1 ,sum;
string s ;
void solve(){
bool check =false ;
int fin =0,suma=0,sumb=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
 if(s[i]=='0')suma++ ;
 else sumb++ ;
}
int a =0,b=0;
for(int i=0;i<n;++i){
 if(suma-sumb==0&&a-b==x){
    cout<<-1<<endl ;
    return ;
 }
 if(suma-sumb){
    int temp =suma-sumb;
 if((x-b+a)%temp==0&&(x-b+a)/temp>=0)
        fin++;

}
if(s[i]=='0')a++ ;
else b++ ;
}
cout<<fin<<endl ;
}
int main() {
    #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin) ;
  #endif
int t ; cin>>t ;
while(t--){
        solve() ;
}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fin ,n ,x, c0,c1 ,sum;
string s ;
void solve(){
bool check =false ;
int fin =0,suma=0,sumb=0 ;
cin>>n>>x ; cin>>s ;
for(int i=0;i<n;++i){
 if(s[i]=='0')suma++ ;
 else sumb++ ;
}
int a =0,b=0;
for(int i=0;i<n;++i){
 if(suma-sumb==0&&a-b==x){
    cout<<-1<<endl ;
    return ;
 }
 if(suma-sumb){
    int temp =suma-sumb;
 if((x+a-b)%temp==0&&(x+a-b)/temp>=0)
        fin++;

}
if(s[i]=='0')a++ ;
else b++ ;
}
cout<<fin<<endl ;
}
int main() {
    #ifndef ONLINE_JUDGE
  freopen("in.txt","r",stdin) ;
  #endif
int t ; cin>>t ;
while(t--){
        solve() ;
}
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
char str[100010];
int b[100010];
int main(){
	int cn,l,x,mx,mn;
	scanf("%d",&cn);
	while(cn--){
		scanf("%d%d%s",&l,&x,str+1);
		mx=mn=0;
		b[0]=0;
		for(int i=1;i<=l;i++){
			b[i]=b[i-1]-str[i]*2+'0'+'1';
			mx=max(mx,b[i]);
			mn=min(mn,b[i]);
			//printf("%d%c",b[i],i==l?'\n':' ');
		}
		if(b[l]==0) printf(mx>=x&&mn<=x?"-1\n":"0\n");
		else {
			int ans=0;
			for(int i=0;i<l;i++){
				if((x-b[i])%b[l]==0&&(x-b[i])/b[l]>=0){
					++ans;
				}
			}
			printf("%d\n",ans);
		}
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
char str[100010];
int b[400020];
#define bal(n) (n>=0?b[n]:b[200010-n])
#define updh(o,n) (o<(n)&&(o=(n)))
#define updl(o,n) (o>(n)&&(o=(n)))
void solve(){
	int l,q,mn=0,mx=0,now=0;
	long long cnt=0;
	scanf("%d%d%s",&l,&q,str);
	for(int i=0;i<400020;i++){
		b[i]=0;
	}
	for(int i=0;i<l;i++){
		bal(now)++;
		if(str[i]=='0'){
			now++;
		} else {
			now--;
		}
		updh(mx,now);
		updl(mn,now);
	}
	if(now>0){
		if(q>mn){
			q-=((q-mn-1)/now)*now;
		}
		for(int i=0;i-mn<=q;i+=now){
			cnt+=bal(q-i);
		}
	} else if(now<0){
		if(q<mx){
			q+=((mx-q-1)/now)*now;
		}
		for(int i=0;i+mx>=q;i+=now){
			cnt+=bal(q-i);
		}
	} else {
		if(mn<=cnt&&cnt<=mx){
			cnt=-1;
		} else {
			cnt=0;
		}
	}
	printf("%d\n",cnt);
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		solve();
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
char str[100010];
int b[200020];
#define bal(n) (n>=0?b[n]:b[100010+n])
#define updh(o,n) (o<(n)&&(o=(n)))
#define updl(o,n) (o>(n)&&(o=(n)))
void solve(){
	int l,q,mn=0,mx=0,now=0;
	long long cnt=0;
	scanf("%d%d%s",&l,&q,str);
	memset(b,0,200020*sizeof(int));
	for(int i=0;i<l;i++){
		bal(now)++;
		if(str[i]=='0'){
			now++;
		} else {
			now--;
		}
		updh(mx,now);
		updl(mn,now);
	}
	if(now>0){
		for(int i=0;i-mn<=q;i+=now){
			cnt+=bal(q-i);
		}
	} else if(now<0){
		for(int i=0;i+mx>=q;i+=now){
			cnt+=bal(q-i);
		}
	} else {
		if(mn<=cnt&&cnt<=mx){
			cnt=-1;
		} else {
			cnt=0;
		}
	}
	printf("%d\n",cnt);
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		solve();
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
char str[100010];
int b[400020];
#define balance(n) (n>=0?b[n]:b[200010-n])
#define updh(o,n) (o<(n)&&(o=(n)))
#define updl(o,n) (o>(n)&&(o=(n)))
void solve(){
	int l,q,mn=0,mx=0,now=0;
	long long cnt=0;
	scanf("%d%d%s",&l,&q,str);
	for(int i=0;i<400020;i++){
		b[i]=0;
	}
	for(int i=0;i<l;i++){
		balance(now)++;
		updh(mx,now);
		updl(mn,now);
		if(str[i]=='0'){
			now++;
		} else {
			now--;
		}
	}
	updh(mx,now);
	updl(mn,now);
	if(now>0){
		if(q>mx){
			q-=((q-mx)/now)*now;
		}
		for(int i=0;i-mn<=q;i+=now){
			cnt+=balance(q-i);
		}
	} else if(now<0){
		if(q<mn){
			q+=((mn-q)/now)*now;
		}
		for(int i=0;i+mx>=q;i+=now){
			cnt+=balance(q-i);
		}
	} else {
		if(mn<=cnt&&cnt<=mx){
			cnt=-1;
		} else {
			cnt=0;
		}
	}
	printf("%d\n",cnt);
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		solve();
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
char str[100010];
int b[400020];
#define balance(n) (n>=0?b[n]:b[200010-n])
#define updh(o,n) (o<(n)&&(o=(n)))
#define updl(o,n) (o>(n)&&(o=(n)))
void solve(){
	int l,q,mn=0,mx=0,now=0;
	long long cnt=0;
	scanf("%d%d%s",&l,&q,str);
	for(int i=0;i<400020;i++){
		b[i]=0;
	}
	for(int i=0;i<l;i++){
		balance(now)++;
		updh(mx,now);
		updl(mn,now);
		if(str[i]=='0'){
			now++;
		} else {
			now--;
		}
	}
	updh(mx,now);
	updl(mn,now);
	if(now>0){
		if(q>mx){
			q-=((q-mx)/now)*now;
		}
		for(int i=0;i-mn<=q;i+=now){
			cnt+=balance(q-i);
		}
	} else if(now<0){
		if(q<mn){
			q+=((mn-q)/now)*now;
		}
		for(int i=0;i+mx>=q;i+=now){
			cnt+=balance(q-i);
		}
	} else {
		if(mn<=cnt&&cnt<=mx){
			cnt=-1;
		} else {
			cnt=0;
		}
	}
	if(q==0&&cnt>0) cnt--;
	printf("%d\n",cnt);
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		solve();
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
char str[100010];
int b[200020];
#define bal(n) (n>=0?b[n]:b[100010-n])
#define updh(o,n) (o<(n)&&(o=(n)))
#define updl(o,n) (o>(n)&&(o=(n)))
void solve(){
	int l,q,mn=0,mx=0,now=0;
	long long cnt=0;
	scanf("%d%d%s",&l,&q,str);
	for(int i=0;i<200020;i++){
		b[i]=0;
	}
	for(int i=0;i<l;i++){
		bal(now)++;
		if(str[i]=='0'){
			now++;
		} else {
			now--;
		}
		updh(mx,now);
		updl(mn,now);
	}
	if(now>0){
		for(int i=0;i-mn<=q;i+=now){
			cnt+=bal(q-i);
		}
	} else if(now<0){
		for(int i=0;i+mx>=q;i+=now){
			cnt+=bal(q-i);
		}
	} else {
		if(mn<=cnt&&cnt<=mx){
			cnt=-1;
		} else {
			cnt=0;
		}
	}
	printf("%d\n",cnt);
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		solve();
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
char str[100010];
int b[400020];
#define bal(n) (n>=0?b[n]:b[200010-n])
#define updh(o,n) (o<(n)&&(o=(n)))
#define updl(o,n) (o>(n)&&(o=(n)))
void solve(){
	int l,q,mn=0,mx=0,now=0;
	long long cnt=0;
	scanf("%d%d%s",&l,&q,str);
	for(int i=0;i<400020;i++){
		b[i]=0;
	}
	for(int i=0;i<l;i++){
		bal(now)++;
		if(str[i]=='0'){
			now++;
		} else {
			now--;
		}
		updh(mx,now);
		updl(mn,now);
	}
	if(now>0){
		if(q>mx){
			q-=((q-mx)/now)*now;
		}
		for(int i=0;i-mn<=q;i+=now){
			cnt+=bal(q-i);
		}
	} else if(now<0){
		if(q<mn){
			q+=((mn-q)/now)*now;
		}
		for(int i=0;i+mx>=q;i+=now){
			cnt+=bal(q-i);
		}
	} else {
		if(mn<=cnt&&cnt<=mx){
			cnt=-1;
		} else {
			cnt=0;
		}
	}
	printf("%d\n",cnt);
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		solve();
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
char str[100010];
int b[400020];
#define bal(n) (n>=0?b[n]:b[200010-n])
#define updh(o,n) (o<(n)&&(o=(n)))
#define updl(o,n) (o>(n)&&(o=(n)))
void solve(){
	int l,q,mn=0,mx=0,now=0;
	long long cnt=0;
	scanf("%d%d%s",&l,&q,str);
	for(int i=0;i<400020;i++){
		b[i]=0;
	}
	for(int i=0;i<l;i++){
		bal(now)++;
		if(str[i]=='0'){
			now++;
		} else {
			now--;
		}
		updh(mx,now);
		updl(mn,now);
	}
	if(now>0){
		if(q>mx){
			q-=((q-mx-1)/now)*now;
		}
		for(int i=0;i-mn<=q;i+=now){
			cnt+=bal(q-i);
		}
	} else if(now<0){
		if(q<mn){
			q+=((mn-q-1)/now)*now;
		}
		for(int i=0;i+mx>=q;i+=now){
			cnt+=bal(q-i);
		}
	} else {
		if(mn<=cnt&&cnt<=mx){
			cnt=-1;
		} else {
			cnt=0;
		}
	}
	printf("%d\n",cnt);
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		solve();
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
char str[100010];
int b[200020];
#define bal(n) (n>=0?b[n]:b[100010-n])
#define updh(o,n) (o<(n)&&(o=(n)))
#define updl(o,n) (o>(n)&&(o=(n)))
void solve(){
	int l,q,mn=0,mx=0,now=0;
	long long cnt=0;
	scanf("%d%d%s",&l,&q,str);
	memset(b,0,200020*sizeof(int));
	for(int i=0;i<l;i++){
		bal(now)++;
		if(str[i]=='0'){
			now++;
		} else {
			now--;
		}
		updh(mx,now);
		updl(mn,now);
	}
	if(now>0){
		for(int i=0;i-mn<=q;i+=now){
			cnt+=bal(q-i);
		}
	} else if(now<0){
		for(int i=0;i+mx>=q;i+=now){
			cnt+=bal(q-i);
		}
	} else {
		if(mn<=cnt&&cnt<=mx){
			cnt=-1;
		} else {
			cnt=0;
		}
	}
	printf("%d\n",cnt);
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		solve();
	}
	return 0;
}


// Problem : B. Infinite Prefixes
// Contest : Codeforces - Educational Codeforces Round 81 (Rated for Div. 2)
// URL : https://codeforces.com/contest/1295/problem/B
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define MOD (1000000007LL)
#define inf 1e12
#define ninf -1e12
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define f first
#define s second
const int N = 2*1e5 + 4;
int add(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) + (b % m)) % m;
  res %= m;
  return res;
}

int mul(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) * (b % m)) % m;
  res %= m;
  return res;
}

int sub(int a, int b, int m){
  int res = (a - b + m) % m;
  res %= m;
  return res;
}

int32_t main(){
	FIO
	int t;
	cin >> t;
	// int c = 1;
	while(t--){
		int n,x;
		cin >> n >> x;
		string s;
		cin >> s;
			vector<int> pref(n+1,0);
		for (int i = 1; i <= n; i++){
			if(s[i-1] == '0') pref[i] += pref[i-1] + 1;
			else pref[i] += pref[i-1] - 1;
		}
		cerr << pref[n] << endl;
		if((x < 0 and pref[n] > 0) or (x > 0 and pref[n] < 0)){
						int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			cout << res << endl;
			continue;
		}
		if(pref[n] == 0){
			int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			if(res){
				cout << "-1" << endl;
			}
			else cout << "0" << endl;
			continue;
		}
		// cerr << "a";
		int res = 0;
		for (int i = 1; i <= n; i++){
			if(abs(x - pref[i]) % abs(pref[n]) == 0) {
				if((x-pref[i])/pref[n] >= 0)
				res++;
				// cerr << i << " " << pref[i] << endl;
			}
		}
		cout << res << endl;
	}
	return 0;
}


// Problem : B. Infinite Prefixes
// Contest : Codeforces - Educational Codeforces Round 81 (Rated for Div. 2)
// URL : https://codeforces.com/contest/1295/problem/B
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define MOD (1000000007LL)
#define inf 1e12
#define ninf -1e12
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define f first
#define s second
const int N = 2*1e5 + 4;
int add(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) + (b % m)) % m;
  res %= m;
  return res;
}

int mul(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) * (b % m)) % m;
  res %= m;
  return res;
}

int sub(int a, int b, int m){
  int res = (a - b + m) % m;
  res %= m;
  return res;
}

int32_t main(){
	FIO
	int t;
	cin >> t;
	int c = 1;
	while(t--){
		int n,x;
		cin >> n >> x;
		string s;
		cin >> s;
		if(c == 32){
			cout << x << " " << s;
			continue;
		}
			vector<int> pref(n+1,0);
		for (int i = 1; i <= n; i++){
			if(s[i-1] == '0') pref[i] += pref[i-1] + 1;
			else pref[i] += pref[i-1] - 1;
		}
		if(pref[n] == x){
			cout << "-1\n";
			continue;
		}
		if((x < 0 and pref[n] > 0) or (x > 0 and pref[n] < 0)){
						cout << "0\n";
			continue;
		}
		if(pref[n] == 0){
			int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			if(res){
				cout << "-1" << endl;
			}
			else cout << "0" << endl;
			continue;
		}
		if(x%pref[n] == 0){
			int tmp1 = x/pref[n] - 1;
			// cerr << tmp1 << endl;
			int tmp2 = tmp1 * pref[n];
			int res = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			tmp2 += pref[n];
 			for (int i = 0; i < n; i++) {
 				if(tmp2+pref[i+1] == x) res++;
 			}
 			cout << res << endl;
		}
		else{
			int tmp1 = x/pref[n];
			int tmp2 = tmp1 * pref[n];
			int res = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			tmp2 += pref[n];
 			for (int i = 0; i < n; i++) {
 				if(tmp2+pref[i+1] == x) res++;
 			}
 			cout << res << endl;
		}
	}
	return 0;
}


// Problem : B. Infinite Prefixes
// Contest : Codeforces - Educational Codeforces Round 81 (Rated for Div. 2)
// URL : https://codeforces.com/contest/1295/problem/B
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define MOD (1000000007LL)
#define inf 1e12
#define ninf -1e12
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define f first
#define s second
const int N = 2*1e5 + 4;
int add(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) + (b % m)) % m;
  res %= m;
  return res;
}

int mul(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) * (b % m)) % m;
  res %= m;
  return res;
}

int sub(int a, int b, int m){
  int res = (a - b + m) % m;
  res %= m;
  return res;
}

int32_t main(){
	FIO
	int t;
	cin >> t;
	// int c = 1;
	while(t--){
		int n,x;
		cin >> n >> x;
		string s;
		cin >> s;
			vector<int> pref(n+1,0);
		for (int i = 1; i <= n; i++){
			if(s[i-1] == '0') pref[i] += pref[i-1] + 1;
			else pref[i] += pref[i-1] - 1;
		}
		if(pref[n] == x){
			cout << "-1\n";
			continue;
		}
		if((x < 0 and pref[n] > 0) or (x > 0 and pref[n] < 0)){
						int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			cout << res << endl;
			continue;
		}
		if(pref[n] == 0){
			int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			if(res){
				cout << "-1" << endl;
			}
			else cout << "0" << endl;
			continue;
		}
		int res = 0;
		for (int i = 1; i <= n; i++){
			if((x - pref[i]) % pref[n] == 0) res++;
		}
		cout << res << endl;
	}
	return 0;
}


// Problem : B. Infinite Prefixes
// Contest : Codeforces - Educational Codeforces Round 81 (Rated for Div. 2)
// URL : https://codeforces.com/contest/1295/problem/B
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define MOD (1000000007LL)
#define inf 1e12
#define ninf -1e12
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define f first
#define s second
const int N = 2*1e5 + 4;
int add(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) + (b % m)) % m;
  res %= m;
  return res;
}

int mul(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) * (b % m)) % m;
  res %= m;
  return res;
}

int sub(int a, int b, int m){
  int res = (a - b + m) % m;
  res %= m;
  return res;
}

int32_t main(){
	FIO
	int t;
	cin >> t;
	// int c = 1;
	while(t--){
		int n,x;
		cin >> n >> x;
		string s;
		cin >> s;
		if(s== "0" and x == 0){
			cout << "1\n";
			continue;
		}
			vector<int> pref(n+1,0);
		for (int i = 1; i <= n; i++){
			if(s[i-1] == '0') pref[i] += pref[i-1] + 1;
			else pref[i] += pref[i-1] - 1;
		}
		// cerr << pref[n] << endl;
		if((x < 0 and pref[n] > 0) or (x > 0 and pref[n] < 0)){
						int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			cout << res << endl;
			continue;
		}
		if(pref[n] == 0){
			int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			if(res){
				cout << "-1" << endl;
			}
			else cout << "0" << endl;
			continue;
		}
		// cerr << "a";
		int res = 0;
		for (int i = 1; i <= n; i++){
			if(abs(x - pref[i]) % abs(pref[n]) == 0) {
				if((x-pref[i])/pref[n] >= 0)
				res++;
				// cerr << i << " " << pref[i] << endl;
			}
		}
		if(x==0) res++;
		cout << res << endl;
	}
	return 0;
}


// Problem : B. Infinite Prefixes
// Contest : Codeforces - Educational Codeforces Round 81 (Rated for Div. 2)
// URL : https://codeforces.com/contest/1295/problem/B
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define MOD (1000000007LL)
#define inf 1e12
#define ninf -1e12
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define f first
#define s second
const int N = 2*1e5 + 4;
int add(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) + (b % m)) % m;
  res %= m;
  return res;
}

int mul(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) * (b % m)) % m;
  res %= m;
  return res;
}

int sub(int a, int b, int m){
  int res = (a - b + m) % m;
  res %= m;
  return res;
}

int32_t main(){
	FIO
	int t;
	cin >> t;
	while(t--){
		int n,x;
		cin >> n >> x;
		string s;
		cin >> s;
		vector<int> pref(n+1,0);
		for (int i = 1; i <= n; i++){
			if(s[i-1] == '0') pref[i] += pref[i-1] + 1;
			else pref[i] += pref[i-1] - 1;
		}
		if(pref[n] == x){
			cout << "-1\n";
			continue;
		}
		if((x < 0 and pref[n] > 0) or (x > 0 and pref[n] < 0)){
						cout << "0\n";
			continue;
		}
		if(pref[n] == 0){
			int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			if(res){
				cout << "-1" << endl;
			}
			else cout << "0" << endl;
			continue;
		}
		if(x%pref[n] == 0){
			int tmp1 = x/pref[n] - 1;
			// cerr << tmp1 << endl;
			int tmp2 = tmp1 * pref[n];
			int res = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			tmp2 += pref[n];
 			for (int i = 0; i < n; i++) {
 				if(tmp2+pref[i+1] == x) res++;
 			}
 			cout << res << endl;
		}
		else{
			int tmp1 = x/pref[n];
			int tmp2 = tmp1 * pref[n];
			int res = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			tmp2 += pref[n];
 			for (int i = 0; i < n; i++) {
 				if(tmp2+pref[i+1] == x) res++;
 			}
 			cout << res << endl;
		}
	}
	return 0;
}


// Problem : B. Infinite Prefixes
// Contest : Codeforces - Educational Codeforces Round 81 (Rated for Div. 2)
// URL : https://codeforces.com/contest/1295/problem/B
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define MOD (1000000007LL)
#define inf 1e12
#define ninf -1e12
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define f first
#define s second
const int N = 2*1e5 + 4;
int add(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) + (b % m)) % m;
  res %= m;
  return res;
}

int mul(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) * (b % m)) % m;
  res %= m;
  return res;
}

int sub(int a, int b, int m){
  int res = (a - b + m) % m;
  res %= m;
  return res;
}

int32_t main(){
	FIO
	int t;
	cin >> t;
	int c = 1;
	while(t--){
		int n,x;
		cin >> n >> x;
		string s;
		cin >> s;
		if(c == 32){
			cout << s;
			continue;
		}
		c++;
			vector<int> pref(n+1,0);
		for (int i = 1; i <= n; i++){
			if(s[i-1] == '0') pref[i] += pref[i-1] + 1;
			else pref[i] += pref[i-1] - 1;
		}
		if(pref[n] == x){
			cout << "-1\n";
			continue;
		}
		if((x < 0 and pref[n] > 0) or (x > 0 and pref[n] < 0)){
						cout << "0\n";
			continue;
		}
		if(pref[n] == 0){
			int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			if(res){
				cout << "-1" << endl;
			}
			else cout << "0" << endl;
			continue;
		}
		if(x%pref[n] == 0){
			int tmp1 = x/pref[n] - 1;
			// cerr << tmp1 << endl;
			int tmp2 = tmp1 * pref[n];
			int res = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			tmp2 += pref[n];
 			for (int i = 0; i < n; i++) {
 				if(tmp2+pref[i+1] == x) res++;
 			}
 			cout << res << endl;
		}
		else{
			int tmp1 = x/pref[n];
			int tmp2 = tmp1 * pref[n];
			int res = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			tmp2 += pref[n];
 			for (int i = 0; i < n; i++) {
 				if(tmp2+pref[i+1] == x) res++;
 			}
 			cout << res << endl;
		}
	}
	return 0;
}


// Problem : B. Infinite Prefixes
// Contest : Codeforces - Educational Codeforces Round 81 (Rated for Div. 2)
// URL : https://codeforces.com/contest/1295/problem/B
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define MOD (1000000007LL)
#define inf 1e12
#define ninf -1e12
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define f first
#define s second
const int N = 2*1e5 + 4;
int add(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) + (b % m)) % m;
  res %= m;
  return res;
}

int mul(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) * (b % m)) % m;
  res %= m;
  return res;
}

int sub(int a, int b, int m){
  int res = (a - b + m) % m;
  res %= m;
  return res;
}

int32_t main(){
	FIO
	int t;
	cin >> t;
	// int c = 1;
	while(t--){
		int n,x;
		cin >> n >> x;
		string s;
		cin >> s;
			vector<int> pref(n+1,0);
		for (int i = 1; i <= n; i++){
			if(s[i-1] == '0') pref[i] += pref[i-1] + 1;
			else pref[i] += pref[i-1] - 1;
		}
		// cerr << pref[n] << endl;
		if((x < 0 and pref[n] > 0) or (x > 0 and pref[n] < 0)){
						int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			cout << res << endl;
			continue;
		}
		if(pref[n] == 0){
			int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			if(res){
				cout << "-1" << endl;
			}
			else cout << "0" << endl;
			continue;
		}
		int res = 0;
		for (int i = 1; i <= n; i++){
			if((x - pref[i]) % pref[n] == 0) res++;
		}
		cout << res << endl;
	}
	return 0;
}


// Problem : B. Infinite Prefixes
// Contest : Codeforces - Educational Codeforces Round 81 (Rated for Div. 2)
// URL : https://codeforces.com/contest/1295/problem/B
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define MOD (1000000007LL)
#define inf 1e12
#define ninf -1e12
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define f first
#define s second
const int N = 2*1e5 + 4;
int add(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) + (b % m)) % m;
  res %= m;
  return res;
}

int mul(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) * (b % m)) % m;
  res %= m;
  return res;
}

int sub(int a, int b, int m){
  int res = (a - b + m) % m;
  res %= m;
  return res;
}

int32_t main(){
	FIO
	int t;
	cin >> t;
	while(t--){
		int n,x;
		cin >> n >> x;
		string s;
		cin >> s;
		vector<int> pref(n+1,0);
		for (int i = 1; i <= n; i++){
			if(s[i-1] == '0') pref[i] += pref[i-1] + 1;
			else pref[i] += pref[i-1] - 1;
		}
		if(pref[n] == x){
			cout << "-1\n";
			continue;
		}
		if((x < 0 and pref[n] > 0) or (x > 0 and pref[n] < 0)){
						cout << "0\n";
			continue;
		}
		if(pref[n] == 0){
			int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			cout << res << endl;
			continue;
		}
		if(x%pref[n] == 0){
			int tmp1 = x/pref[n] - 1;
			// cerr << tmp1 << endl;
			int tmp2 = tmp1 * pref[n];
			int res = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			tmp2 += pref[n];
 			for (int i = 0; i < n; i++) {
 				if(tmp2+pref[i+1] == x) res++;
 			}
 			cout << res << endl;
		}
		else{
			int tmp1 = x/pref[n];
			int tmp2 = tmp1 * pref[n];
			int res = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			tmp2 += pref[n];
 			for (int i = 0; i < n; i++) {
 				if(tmp2+pref[i+1] == x) res++;
 			}
 			cout << res << endl;
		}
	}
	return 0;
}


// Problem : B. Infinite Prefixes
// Contest : Codeforces - Educational Codeforces Round 81 (Rated for Div. 2)
// URL : https://codeforces.com/contest/1295/problem/B
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define MOD (1000000007LL)
#define inf 1e12
#define ninf -1e12
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define f first
#define s second
const int N = 2*1e5 + 4;
int add(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) + (b % m)) % m;
  res %= m;
  return res;
}

int mul(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) * (b % m)) % m;
  res %= m;
  return res;
}

int sub(int a, int b, int m){
  int res = (a - b + m) % m;
  res %= m;
  return res;
}

int32_t main(){
	FIO
	int t;
	cin >> t;
	// int c = 1;
	while(t--){
		int n,x;
		cin >> n >> x;
		string s;
		cin >> s;
		if(s== "0" and x == 0){
			cout << "1\n";
			continue;
		}
			vector<int> pref(n+1,0);
		for (int i = 1; i <= n; i++){
			if(s[i-1] == '0') pref[i] += pref[i-1] + 1;
			else pref[i] += pref[i-1] - 1;
		}
		// cerr << pref[n] << endl;
		if((x < 0 and pref[n] > 0) or (x > 0 and pref[n] < 0)){
						int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			cout << res << endl;
			continue;
		}
		if(pref[n] == 0){
			int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			if(res){
				cout << "-1" << endl;
			}
			else cout << "0" << endl;
			continue;
		}
		// cerr << "a";
		int res = 0;
		for (int i = 1; i <= n; i++){
			if(abs(x - pref[i]) % abs(pref[n]) == 0) {
				if((x-pref[i])/pref[n] >= 0)
				res++;
				// cerr << i << " " << pref[i] << endl;
			}
		}
		cout << res << endl;
	}
	return 0;
}


// Problem : B. Infinite Prefixes
// Contest : Codeforces - Educational Codeforces Round 81 (Rated for Div. 2)
// URL : https://codeforces.com/contest/1295/problem/B
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define MOD (1000000007LL)
#define inf 1e12
#define ninf -1e12
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define f first
#define s second
const int N = 2*1e5 + 4;
int add(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) + (b % m)) % m;
  res %= m;
  return res;
}

int mul(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) * (b % m)) % m;
  res %= m;
  return res;
}

int sub(int a, int b, int m){
  int res = (a - b + m) % m;
  res %= m;
  return res;
}

int32_t main(){
	FIO
	int t;
	cin >> t;
	while(t--){
		int n,x;
		cin >> n >> x;
		string s;
		cin >> s;
		vector<int> pref(n+1,0);
		for (int i = 1; i <= n; i++){
			if(s[i-1] == '0') pref[i] += pref[i-1] + 1;
			else pref[i] += pref[i-1] - 1;
		}
		if(pref[n] == x){
			cout << "-1\n";
			continue;
		}
		if((x < 0 and pref[n] > 0) or (x > 0 and pref[n] < 0)){
						cout << "0\n";
			continue;
		}
		if(x%pref[n] == 0){

			int tmp1 = x/pref[n] - 1;
			cerr << tmp1 << endl;
			int tmp2 = tmp1 * pref[n];
			int res = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			tmp2 += pref[n];
 			for (int i = 0; i < n; i++) {
 				if(tmp2+pref[i+1] == x) res++;
 			}
 			cout << res << endl;
		}
		else{
			int tmp1 = x/pref[n];
			int tmp2 = tmp1 * pref[n];
			int res = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			tmp2 += pref[n];
 			for (int i = 0; i < n; i++) {
 				if(tmp2+pref[i+1] == x) res++;
 			}
 			cout << res << endl;
		}
	}
	return 0;
}


// Problem : B. Infinite Prefixes
// Contest : Codeforces - Educational Codeforces Round 81 (Rated for Div. 2)
// URL : https://codeforces.com/contest/1295/problem/B
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define MOD (1000000007LL)
#define inf 1e12
#define ninf -1e12
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define f first
#define s second
const int N = 2*1e5 + 4;
int add(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) + (b % m)) % m;
  res %= m;
  return res;
}

int mul(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) * (b % m)) % m;
  res %= m;
  return res;
}

int sub(int a, int b, int m){
  int res = (a - b + m) % m;
  res %= m;
  return res;
}

int32_t main(){
	FIO
	int t;
	cin >> t;
	// int c = 1;
	while(t--){
		int n,x;
		cin >> n >> x;
		string s;
		cin >> s;
		if(s== "0" and x == 0){
			cout << "1\n";
			continue;
		}
			vector<int> pref(n+1,0);
		for (int i = 1; i <= n; i++){
			if(s[i-1] == '0') pref[i] += pref[i-1] + 1;
			else pref[i] += pref[i-1] - 1;
		}
		// cerr << pref[n] << endl;

		if(pref[n] == 0){
			int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			if(res){
				cout << "-1" << endl;
			}
			else cout << "0" << endl;
			continue;
		}
		// cerr << "a";
		int res = 0;
		for (int i = 1; i <= n; i++){
			if(abs(x - pref[i]) % abs(pref[n]) == 0) {
				if((x-pref[i])/pref[n] >= 0)
				res++;
				// cerr << i << " " << pref[i] << endl;
			}
		}
		if(x==0) res++;
		cout << res << endl;
	}
	return 0;
}


// Problem : B. Infinite Prefixes
// Contest : Codeforces - Educational Codeforces Round 81 (Rated for Div. 2)
// URL : https://codeforces.com/contest/1295/problem/B
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define MOD (1000000007LL)
#define inf 1e12
#define ninf -1e12
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define f first
#define s second
const int N = 2*1e5 + 4;
int add(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) + (b % m)) % m;
  res %= m;
  return res;
}

int mul(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) * (b % m)) % m;
  res %= m;
  return res;
}

int sub(int a, int b, int m){
  int res = (a - b + m) % m;
  res %= m;
  return res;
}

int32_t main(){
	FIO
	int t;
	cin >> t;
	while(t--){
		int n,x;
		cin >> n >> x;
		string s;
		cin >> s;
		vector<int> pref(n+1,0);
		for (int i = 1; i <= n; i++){
			if(s[i-1] == '0') pref[i] += pref[i-1] + 1;
			else pref[i] += pref[i-1] - 1;
		}
		if(pref[n] == x){
			cout << "-1\n";
			continue;
		}
		if((x < 0 and pref[n] > 0) or (x > 0 and pref[n] < 0)){
						cout << "0\n";
			continue;
		}
		if(pref[n] == 0){
			int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
		}
		if(x%pref[n] == 0){
			int tmp1 = x/pref[n] - 1;
			// cerr << tmp1 << endl;
			int tmp2 = tmp1 * pref[n];
			int res = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			tmp2 += pref[n];
 			for (int i = 0; i < n; i++) {
 				if(tmp2+pref[i+1] == x) res++;
 			}
 			cout << res << endl;
		}
		else{
			int tmp1 = x/pref[n];
			int tmp2 = tmp1 * pref[n];
			int res = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			tmp2 += pref[n];
 			for (int i = 0; i < n; i++) {
 				if(tmp2+pref[i+1] == x) res++;
 			}
 			cout << res << endl;
		}
	}
	return 0;
}


// Problem : B. Infinite Prefixes
// Contest : Codeforces - Educational Codeforces Round 81 (Rated for Div. 2)
// URL : https://codeforces.com/contest/1295/problem/B
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define FIO ios_base::sync_with_stdio(0); cin.tie(0);
#define MOD (1000000007LL)
#define inf 1e12
#define ninf -1e12
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define f first
#define s second
const int N = 2*1e5 + 4;
int add(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) + (b % m)) % m;
  res %= m;
  return res;
}

int mul(int a, int b, int m){
  if(a < 0) a += m;
  if(b < 0) b += m;
  int res = ((a % m) * (b % m)) % m;
  res %= m;
  return res;
}

int sub(int a, int b, int m){
  int res = (a - b + m) % m;
  res %= m;
  return res;
}

int32_t main(){
	FIO
	int t;
	cin >> t;
	int c = 1;
	while(t--){
		int n,x;
		cin >> n >> x;
		string s;
		cin >> s;
		if(c == 32){
			cout << x << " " << s;
			continue;
		}
		c++;
			vector<int> pref(n+1,0);
		for (int i = 1; i <= n; i++){
			if(s[i-1] == '0') pref[i] += pref[i-1] + 1;
			else pref[i] += pref[i-1] - 1;
		}
		if(pref[n] == x){
			cout << "-1\n";
			continue;
		}
		if((x < 0 and pref[n] > 0) or (x > 0 and pref[n] < 0)){
						cout << "0\n";
			continue;
		}
		if(pref[n] == 0){
			int res = 0;
			int tmp2 = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			if(res){
				cout << "-1" << endl;
			}
			else cout << "0" << endl;
			continue;
		}
		if(x%pref[n] == 0){
			int tmp1 = x/pref[n] - 1;
			// cerr << tmp1 << endl;
			int tmp2 = tmp1 * pref[n];
			int res = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			tmp2 += pref[n];
 			for (int i = 0; i < n; i++) {
 				if(tmp2+pref[i+1] == x) res++;
 			}
 			cout << res << endl;
		}
		else{
			int tmp1 = x/pref[n];
			int tmp2 = tmp1 * pref[n];
			int res = 0;
			for (int i = 0; i < n; i++){
				if(tmp2+pref[i+1] == x) res++;
			}
			tmp2 += pref[n];
 			for (int i = 0; i < n; i++) {
 				if(tmp2+pref[i+1] == x) res++;
 			}
 			cout << res << endl;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;

	for (; t > 0; --t) {
		int n, x;
		cin >> n >> x;

		string s;
		cin >> s;

		ll d = 0;
		ll r = 0;
		for (int i = 0; i < n; ++i) {
			char c = s[i%n];
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
		}

		if (d == x) {
			int nd = d;
			for (int i = 0; i < n; ++i) {
				char c = s[i%n];
				if (c == '0') ++nd;
				else --nd;
			}
			if (nd == x) {
				cout << "-1\n";
				continue;
			}
		}
		if (d == 0) {
			cout << r << endl;
			continue;
		}
		int m = abs(x/d) - 1;
		d *= max(1, m);
		for (int i = 0; i < 2*n; ++i) {
			char c = s[i%n];
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
		}

		cout << r << '\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;

	for (; t > 0; --t) {
		int n, x;
		cin >> n >> x;

		string s;
		cin >> s;

		map<ll, int> m;
		int d = 0;
		ll r = 0;
		for (auto c : s) {
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
			++m[d];
		}

		if (d == 0) {
			if (r > 0) {
				cout << "-1\n";
				continue;
			} else {
				cout << "0\n";
				continue;
			}
		}
		int e = 1;

		if (abs(x)-n > 0) {
			if (x < 0) e = abs((x+n)/d) - 1;
			else e = abs((x-n)/d) - 1;
		}
		e = max(1, e);

		for (int i = 0; i < n*3; ++i) {
			r += m[x - ((e+i) * d)];
		}

		cout << r << '\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;

	for (; t > 0; --t) {
		ll n, x;
		cin >> n >> x;

		string s;
		cin >> s;

		map<ll, ll> m;
		ll d = 0;
		ll r = 0;
		for (auto c : s) {
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
			++m[d];
		}
		if (d == x) ++r;

		if (d == 0) {
			if (r > 0) {
				cout << "-1\n";
				continue;
			} else {
				cout << "0\n";
				continue;
			}
		}
		ll e = 1;

		if (abs(x)-n > 0) {
			if (x < 0) e = abs((x+n)/d) - 1;
			else e = abs((x-n)/d) - 1;
		}
		e = max((ll)1, e);

		for (int i = 0; i < n*3; ++i) {
			r += m[x - ((e+i) * d)];
		}

		cout << r << '\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;

	for (; t > 0; --t) {
		int n, x;
		cin >> n >> x;

		string s;
		cin >> s;

		map<ll, int> m;
		int d = 0;
		ll r = 0;
		for (auto c : s) {
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
			++m[d];
		}

		if (d == 0) {
			if (r > 0) {
				cout << "-1\n";
				continue;
			} else {
				cout << "0\n";
				continue;
			}
		}
		int n2 = 0;
		if (abs(x) - n > 0) {
			n2 = (abs(x) - n) / abs(d) - 1;
		}
		int dd = d * max(1, n2);
		for (int i = 0; i < n*3; ++i) {
			r += m[x - (dd + i * d)];
		}

		cout << r << '\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;

	for (; t > 0; --t) {
		int n, x;
		cin >> n >> x;

		string s;
		cin >> s;

		ll d = 0;
		ll r = 0;
		for (auto c : s) {
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
		}

		if (d == x) {
			int d2 = d;
			for (auto c : s) {
				if (c == '0') ++d2;
				else --d2;
			}
			if (d2 == x) {
				cout << "-1\n";
				continue;
			}
		}
		if (d == 0) {
			cout << r << endl;
			continue;
		}
		int m = abs(x/d) - 1;
		d *= max(1, m);
		for (int i = 0; i < 3*n; ++i) {
			char c = s[i%n];
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
		}

		cout << r << '\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;

	for (; t > 0; --t) {
		ll n, x;
		cin >> n >> x;

		string s;
		cin >> s;

		map<ll, ll> m;
		ll d = 0;
		ll r = 0;
		for (auto c : s) {
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
			++m[d];
		}

		if (d == 0) {
			if (r > 0) {
				cout << "-1\n";
				continue;
			} else {
				cout << "0\n";
				continue;
			}
		}
		ll e = 1;

		if (abs(x)-n > 0) {
			if (x < 0) e = abs((x+n)/d) - 1;
			else e = abs((x-n)/d) - 1;
		}
		e = max((ll)1, e);

		for (int i = 0; i < n*3; ++i) {
			r += m[x - ((e+i) * d)];
		}

		cout << r << '\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;

	for (; t > 0; --t) {
		int n, x;
		cin >> n >> x;

		string s;
		cin >> s;

		ll d = 0;
		ll r = 0;
		for (auto c : s) {
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
		}

		if (d == x) {
			cout << "-1\n";
			continue;
		}
		if (d != 0) {
			int m = abs(x/d) - 1;
			d *= max(1, m);
		}
		for (int i = 0; i < 2*n; ++i) {
			char c = s[i%n];
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
		}

		cout << r << '\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;

	for (; t > 0; --t) {
		int n, x;
		cin >> n >> x;

		string s;
		cin >> s;

		ll d = 0;
		ll r = 0;
		for (auto c : s) {
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
		}

		if (d == x) {
			cout << "-1\n";
			continue;
		}
		d *= max(1, (int)(abs(x/d)-1));
		for (int i = 0; i < 2*n; ++i) {
			char c = s[i%n];
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
		}

		cout << r << '\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;

	for (; t > 0; --t) {
		int n, x;
		cin >> n >> x;

		string s;
		cin >> s;

		ll d = 0;
		ll r = 0;
		for (auto c : s) {
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
		}

		if (d == 0) {
			if (r > 0) {
				cout << "-1\n";
				continue;
			} else {
				cout << "0\n";
				continue;
			}
		}
		int m = abs(x/d) - 1;
		d *= max(1, m);
		for (int i = 0; i < 3*n; ++i) {
			char c = s[i%n];
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
		}

		cout << r << '\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;

	for (; t > 0; --t) {
		int n, x;
		cin >> n >> x;

		string s;
		cin >> s;

		ll d = 0;
		ll r = 0;
		for (auto c : s) {
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
		}

		if (d == x) {
			cout << "-1\n";
			continue;
		}
		d *= max((ll)1, abs(x/d)-1);
		for (int i = 0; i < 2*n; ++i) {
			char c = s[i%n];
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
		}

		cout << r << '\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;

	for (; t > 0; --t) {
		int n, x;
		cin >> n >> x;

		string s;
		cin >> s;

		map<ll, int> m;
		int d = 0;
		ll r = 0;
		for (auto c : s) {
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
			++m[d];
		}

		if (d == 0) {
			if (r > 0) {
				cout << "-1\n";
				continue;
			} else {
				cout << "0\n";
				continue;
			}
		}
		int n2 = 0;
		if (abs(x) - n > 0) {
			n2 = (abs(x) - n) / abs(d);
		}
		int dd = d * max(1, n2);
		for (int i = 0; i < n*2; ++i) {
			r += m[x - (dd + i * d)];
		}

		cout << r << '\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;

	for (; t > 0; --t) {
		ll n, x;
		cin >> n >> x;

		string s;
		cin >> s;

		map<ll, ll> m;
		ll d = 0;
		ll r = 0;
		for (auto c : s) {
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
			++m[d];
		}

		if (d == 0) {
			if (r > 0) {
				cout << "-1\n";
				continue;
			} else {
				cout << "0\n";
				continue;
			}
		}
		ll e = 1;

		if (abs(x)-n > 0) {
			if (x < 0) e = abs((x+n)/d) - 1;
			else e = abs((x-n)/d) - 1;
		}
		e = max(1, e);

		for (int i = 0; i < n*3; ++i) {
			r += m[x - ((e+i) * d)];
		}

		cout << r << '\n';
	}
}


#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin >> t;

	for (; t > 0; --t) {
		int n, x;
		cin >> n >> x;

		string s;
		cin >> s;

		ll d = 0;
		ll r = 0;
		for (auto c : s) {
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
		}

		if (d == 0) {
			if (r > 0) {
				cout << "-1\n";
				continue;
			} else {
				cout << "0\n";
			}
		}
		int m = abs(x/d) - 1;
		d *= max(1, m);
		for (int i = 0; i < 3*n; ++i) {
			char c = s[i%n];
			if (d == x) ++r;
			if (c == '0') ++d;
			else --d;
		}

		cout << r << '\n';
	}
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int n;
long double a,b,c[100010],d[100010],x[100010],y[100010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)cin>>c[i];
	for(int i=1;i<=n;i++)cin>>d[i];
	for(int i=n;i;i--)
	{
		long double B=a-b-c[i]-d[i],C=-a*(c[i]+d[i])+d[i],delta=B*B-4*C;
		if(fabs(delta)<=1e-6)delta=0;
		delta=sqrtl(delta);
		x[i]=(-B+delta)/2;
		if(x[i]<0||x[i]-c[i]-d[i]>=1e-7)x[i]=(-B-delta)/2;
		y[i]=c[i]+d[i]-x[i];
		a+=x[i];b+=y[i];
	}
	for(int i=1;i<=n;i++)printf("%.12lf ",(double)x[i]);
	puts("");
	for(int i=1;i<=n;i++)printf("%.12lf ",(double)y[i]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int n;
long double a,b,c[100010],d[100010],x[100010],y[100010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)cin>>c[i];
	for(int i=1;i<=n;i++)cin>>d[i];
	for(int i=n;i;i--)
	{
		long double B=a-b-c[i]-d[i],C=-a*(c[i]+d[i])+d[i],delta=B*B-4*C;
		if(fabs(delta)<=1e-5)delta=0;
		delta=sqrtl(delta);
		x[i]=(-B+delta)/2,y[i]=c[i]+d[i]-x[i];
		if(fabs(x[i])<=1e-5)x[i]=0;
		if(fabs(y[i])<=1e-5)y[i]=0;
		a+=x[i];b+=y[i];
	}
	for(int i=1;i<=n;i++)printf("%.6lf ",(double)x[i]);
	puts("");
	for(int i=1;i<=n;i++)printf("%.6lf ",(double)y[i]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int n;
double a,b,c[100010],d[100010],x[100010],y[100010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lf",&c[i]),c[i]+=c[i-1];
	for(int i=1;i<=n;i++)scanf("%lf",&d[i]),d[i]+=d[i-1];
	for(int i=1;i<=n;i++)
	{
		double B=c[i]+d[i],C=c[i],delta=B*B-4*C;
		if(fabs(delta)<=1e-6)delta=0;
		delta=sqrt(delta);
		x[i]=(B+delta)/2;
		y[i]=(B-delta)/2;
	}
	for(int i=n;i;i--)x[i]-=x[i-1],y[i]-=y[i-1];
	for(int i=1;i<=n;i++)printf("%.6lf ",y[i]);
	puts("");
	for(int i=1;i<=n;i++)printf("%.6lf ",x[i]);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int n;
long double a,b,c[100010],d[100010],x[100010],y[100010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)cin>>c[i];
	for(int i=1;i<=n;i++)cin>>d[i];
	for(int i=n;i;i--)
	{
		long double B=a-b-c[i]-d[i],C=-a*(c[i]+d[i])+d[i],delta=B*B-4*C;
		if(fabs(delta)<=1e-6)delta=0;
		delta=sqrtl(delta);
		x[i]=(-B+delta)/2;
		if(x[i]<0||x[i]-c[i]-d[i]>=1e-7)x[i]=(-B-delta)/2;
		if(fabs(x[i])<=1e-5)x[i]=0;
		y[i]=c[i]+d[i]-x[i];
		a+=x[i];b+=y[i];
	}
	for(int i=1;i<=n;i++)printf("%.12lf ",(double)x[i]);
	puts("");
	for(int i=1;i<=n;i++)printf("%.12lf ",(double)y[i]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int n;
long double a,b,c[100010],d[100010],x[100010],y[100010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)cin>>c[i];
	for(int i=1;i<=n;i++)cin>>d[i];
	for(int i=n;i;i--)
	{
		long double B=a-b-c[i]-d[i],C=-a*(c[i]+d[i])+d[i],delta=B*B-4*C;
		if(fabs(delta)<=1e-6)delta=0;
		delta=sqrtl(delta);
		x[i]=(-B+delta)/2,y[i]=c[i]+d[i]-x[i];
		if(fabs(x[i])<=1e-6)x[i]=0;
		if(fabs(y[i])<=1e-6)y[i]=0;
		a+=x[i];b+=y[i];
	}
	for(int i=1;i<=n;i++)printf("%.6lf ",(double)x[i]);
	puts("");
	for(int i=1;i<=n;i++)printf("%.6lf ",(double)y[i]);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int n;
double a,b,c[100010],d[100010],x[100010],y[100010];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lf",&c[i]);
	for(int i=1;i<=n;i++)scanf("%lf",&d[i]);
	for(int i=n;i;i--)
	{
		double B=a-b-c[i]-d[i],C=-a*(c[i]+d[i])+d[i];
		x[i]=(-B+sqrt(B*B-4*C+1e-6))/2,y[i]=c[i]+d[i]-x[i];
		a+=x[i];b+=y[i];
	}
	for(int i=1;i<=n;i++)printf("%.6lf ",x[i]);
	puts("");
	for(int i=1;i<=n;i++)printf("%.6lf ",y[i]);
	return 0;
}