#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, x, sum = 0;
    cin >> n >> x;
    string s;
    cin >> s;
    map<long long, long long> map1;
    map1[0] = 1LL;
    for (int i = 0; i < n; i++) {
      if (s[i] == '0')
        sum += 1;
      else
        sum += -1;
      if (i < n - 1) map1[sum]++;
    }
    if (sum == 0) {
      if (map1[x] != 0)
        cout << -1 << "\n";
      else
        cout << 0 << "\n";
    } else {
      long long ans = 0;
      for (auto itr = map1.begin(); itr != map1.end(); itr++) {
        if ((x - itr->first) % sum == 0 && (x - itr->first) * sum >= 0)
          ans += itr->second;
      }
      cout << ans << "\n";
    }
  }
  return 0;
}
