#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("O3")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n, x;
    cin >> n >> x;
    string s;
    cin >> s;
    int a[100001] = {0};
    int b[100001] = {0};
    int f = 0;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '0') {
        a[i + 1] = a[i] + 1;
        b[i + 1] = b[i];
      } else {
        a[i + 1] = a[i];
        b[i + 1] = b[i] + 1;
      }
    }
    long long ans = 0;
    int c0 = 1;
    for (int i = 1; i <= n; i++) {
      if (a[i] - b[i] == 0) {
        c0++;
      }
      int g = a[i] - b[i];
      long double h;
      h = (x - g);
      h *= 1.0;
      if (a[n] - b[n] == 0) {
        if (g == x) ans++;
        continue;
      }
      h /= (long double)(a[n] - b[n]);
      if (h < 0) continue;
      if (ceil(h) == floor(h)) {
        ans++;
      }
    }
    if (a[n] - b[n] == 0) {
      for (int i = 1; i <= n; i++)
        if (a[i] - b[i] == x) {
          cout << -1 << '\n';
          f = 1;
          break;
        }
    }
    if (x == 0) ans++;
    if (f) continue;
    cout << ans << '\n';
  }
}
