#include <bits/stdc++.h>
using namespace std;
int main() {
  map<long long, long long> mp;
  int TC;
  cin >> TC;
  while (TC--) {
    long long n, x;
    cin >> n >> x;
    string s;
    cin >> s;
    long long zero = 0, ones = 0;
    mp[0] = 0;
    for (long long i = 0; i < n; i++) {
      if (s[i] == '0')
        zero++;
      else
        ones++;
      mp[i + 1] = zero - ones;
    }
    zero = zero - ones;
    long long res = 0;
    double k;
    if (zero) {
      for (long long i = 0; i < n; i++) {
        k = (double)(x - mp[i]) / (double)zero;
        if (!(k - floor(k)) && k >= 0) {
          res++;
        }
      }
      cout << res << endl;
    } else {
      for (long long i = 0; i <= n; i++) {
        if (mp[i] == x) res++;
      }
      if (res)
        cout << -1 << endl;
      else
        cout << 0 << endl;
    }
  }
}
