#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 20;
const int inf = 0x3f3f3f3f;
const int modd = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return f * x;
}
template <class T>
inline void sc(T &x) {
  char c;
  x = 0;
  while ((c = getchar()) < '0')
    ;
  while (c >= '0' && c <= '9') x = x * 10 + (c - 48), c = getchar();
}
inline long long gcd(long long a, long long b) {
  return b == 0 ? a : gcd(b, a % b);
}
inline long long exgcd(long long a, long long b, long long &x, long long &y) {
  long long d;
  (b == 0 ? (x = 1, y = 0, d = a)
          : (d = exgcd(b, a % b, y, x), y -= a / b * x));
  return d;
}
inline long long qpow(long long a, long long n) {
  long long sum = 1;
  while (n) {
    if (n & 1) sum = sum * a % modd;
    a = a * a % modd;
    n >>= 1;
  }
  return sum;
}
inline long long qmul(long long a, long long n) {
  long long sum = 0;
  while (n) {
    if (n & 1) sum = (sum + a) % modd;
    a = (a + a) % modd;
    n >>= 1;
  }
  return sum;
}
inline long long inv(long long a) { return qpow(a, modd - 2); }
int tot, cnt, a[maxn];
char s[maxn];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    tot = cnt = 0;
    int n, m;
    scanf("%d%d%s", &n, &m, &s);
    for (int i = 0; i < n; i++)
      if (s[i] == '1')
        a[++tot] = --cnt;
      else
        a[++tot] = ++cnt;
    int flag = 1;
    if (!cnt)
      for (int i = 1; i <= n; i++)
        if (m - a[i] == 0) flag = 0;
    if (!flag) {
      printf("-1\n");
      continue;
    }
    if (!cnt) {
      printf("0\n");
      continue;
    }
    int ans = 0;
    if (!m) ans++;
    for (int i = 1; i <= n; i++) {
      int k = m - a[i];
      int nt = k / cnt;
      if (nt < 0) continue;
      if (nt * cnt == k) ans++;
    }
    printf("%d\n", ans);
  }
}
