#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e6;
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar(), f = 0;
  for (; c < '0' || c > '9'; c = getchar())
    if (c == '-') f = 1;
  for (; c >= '0' && c <= '9'; c = getchar())
    x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
}
int T, n, k, s[100005];
char c[100005];
int main() {
  for (read(T); T--;) {
    read(n), read(k), scanf("%s", c + 1), s[0] = 0;
    long long ans = 0;
    char tag = 0;
    for (int i = 1; i <= n; i++) s[i] = s[i - 1] + (c[i] == '0' ? 1 : -1);
    for (int i = 0; i <= n; i++) {
      if (s[i] == k) ans++;
      if (s[i] == k && !s[n]) tag = 1;
      if (i && s[i] < k && s[n] > 0 && (k - s[i]) % s[n] == 0) ans++;
      if (i && s[i] > k && s[n] < 0 && (s[i] - k) % (-s[n]) == 0) ans++;
    }
    if (tag)
      puts("-1");
    else
      printf("%d\n", ans);
  }
  return 0;
}
