#include <bits/stdc++.h>
using namespace std;
const long long int mxn = 1e6;
string s;
long long int n, x;
long long int calc() {
  long long int cnt = 0;
  long long int bal = 0;
  for (long long int i = 0; i < n; i++) {
    s[i] == '0' ? bal++ : bal--;
    if (bal == x) cnt++;
  }
  if (x == 0) cnt++;
  return cnt;
}
void tc() {
  cin >> n >> x;
  cin >> s;
  long long int ne = 0;
  for (long long int i = 0; i < n; i++) s[i] == '0' ? ne++ : ne--;
  if (ne == 0) {
    long long int c = calc();
    if (c > 0)
      cout << -1 << "\n";
    else
      cout << 0 << "\n";
  } else {
    long long int ce = 0;
    long long int ans = 0;
    for (long long int i = 0; i < n - 1; i++) {
      s[i] == '0' ? ce++ : ce--;
      long long int k = (x - ce) / ne;
      if (k * ne + ce == x && k >= 0) ans++;
    }
    long long int k = (x - 0) / ne;
    if (k * ne + 0 == x and k >= 0) ans++;
    cout << ans << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  t = 1;
  cin >> t;
  while (t--) tc();
}
