#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, x;
  cin >> n >> x;
  string s;
  cin >> s;
  int once = 0;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    m[once]++;
    once += (s[i] == '0') * 2 - 1;
  }
  if (once == 0) {
    if (m.count(x))
      cout << -1 << "\n";
    else
      cout << 0 << "\n";
  } else {
    int ans = 0;
    for (auto &iter : m) {
      if ((x - iter.first) % once == 0) {
        if ((x - iter.first) / once >= 0) {
          ans += iter.second;
        }
      }
    }
    cout << ans << "\n";
  }
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
