#include <bits/stdc++.h>
using namespace std;
const long long int mxn = 1e5 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int i, j, k, n, m;
    cin >> n >> k;
    string s;
    cin >> s;
    map<long long int, long long int> mp;
    long long int sum = 0;
    for (i = 0; i < n; i++) {
      if (s[i] == '0')
        sum++;
      else
        sum--;
      mp[sum]++;
    }
    if (sum == 0 && mp[k])
      cout << -1 << "\n";
    else if (sum == 0)
      cout << 0 << "\n";
    else {
      long long int ans = 0, p = 0;
      if (p == k) {
        ans++;
      }
      for (i = 0; i < n; i++) {
        if (s[i] == '0')
          p++;
        else
          p--;
        if ((k - p) % sum == 0 && ((k - p) / sum) >= 0) {
          ans++;
        }
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
