#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  if (fopen("input.in", "r")) {
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
  }
  int t, n, x, pre[200123], ans;
  bool find;
  string s;
  cin >> t;
  while (t--) {
    find = false;
    ans = 0;
    cin >> n >> x;
    cin >> s;
    if (x == 0) ans++;
    pre[0] = (s[0] == '0') ? 1 : -1;
    find |= (pre[0] == x);
    for (int i = 1; i < n; i++) {
      pre[i] = (pre[i - 1] + ((s[i] == '0') ? 1 : -1));
      find |= (pre[i] == x);
    }
    if (pre[n - 1] == 0) {
      if (find)
        cout << -1;
      else
        cout << 0;
    } else {
      for (int i = 0; i < n; i++) {
        int k = (x - pre[i]) / pre[n - 1];
        if (k >= 0 && k * pre[n - 1] == x - pre[i]) ans++;
      }
      cout << ans;
    }
    cout << endl;
  }
  return 0;
}
