#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  register long long t = 0, f = 0;
  register char v = getchar();
  while (v < '0') f |= (v == '-'), v = getchar();
  while (v >= '0') {
    t = (t << 3) + (t << 1) + v - 48;
    v = getchar();
  }
  return f ? -t : t;
}
long long n, t, x, ans, mx, mn;
char s[100002];
long long mp[200002];
long long cnt0, cnt1;
signed main() {
  t = read();
  while (t--) {
    n = read();
    mx = 0;
    mn = 0;
    x = read();
    memset(mp, 0, sizeof(mp));
    cnt0 = cnt1 = ans = 0;
    scanf("%s", s + 1);
    for (register long long i = 1; i <= n; ++i) {
      if (s[i] == '0')
        ++cnt0;
      else
        ++cnt1;
    }
    long long tmp = cnt0 - cnt1;
    cnt0 = cnt1 = 0;
    if (tmp == 0) {
      bool ia = 0;
      for (register long long i = 1; i <= n; ++i) {
        if (s[i] == '0')
          ++cnt0;
        else
          ++cnt1;
        if (cnt0 - cnt1 == x) {
          puts("-1");
          ia = 1;
          break;
        }
      }
      if (!ia) puts("0");
      continue;
    }
    if (x == 0) ++ans;
    for (register long long i = 1; i <= n; ++i) {
      if (s[i] == '0')
        ++cnt0;
      else
        ++cnt1;
      if ((x - cnt0 + cnt1) * tmp >= 0) {
        if ((x - cnt0 + cnt1) % tmp == 0) ++ans;
      }
    }
    printf("%lld\n", ans);
  }
}
