#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n, x, y = 0, tot = 0, ans = 0;
    cin >> n >> x;
    string s;
    cin >> s;
    if (x == 0) ans++;
    for (long long i = 0; i < n; i++) y += ((s[i] == '0') ? 1 : -1);
    if (x == y && y == 0)
      ans = -1;
    else if (x == y)
      ans++;
    for (long long i = 0; i < n; i++) {
      if (ans == -1) break;
      tot += ((s[i] == '0') ? 1 : -1);
      if (x == tot && y == 0) {
        ans = -1;
        break;
      }
      if (x == tot && i != n - 1) ans++;
      if (y == 0) continue;
      if (abs(x - tot) % abs(y) == 0 && (x - tot) * y > 0) ans++;
    }
    cout << ans << '\n';
  }
  return 0;
}
