#include <bits/stdc++.h>
std::map<int, int> count;
std::map<int, int> vis;
int sum[100005];
void addCount(int u, int add) {
  if (count.count(u)) {
    count[u] += add;
  } else
    count[u] = add;
}
int getCount(int u) {
  if (!count.count(u))
    return 0;
  else
    return count[u];
}
int sameSign(int a, int b) {
  if (a >= 0 && b >= 0)
    return 1;
  else if (a <= 0 && b <= 0)
    return 1;
  else
    return 0;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    count.clear();
    vis.clear();
    int n, x;
    scanf("%d%d", &n, &x);
    sum[0] = 0;
    for (int i = 1; i <= n; i++) {
      int u;
      scanf("%1d", &u);
      if (u == 0)
        sum[i] = sum[i - 1] + 1;
      else
        sum[i] = sum[i - 1] - 1;
      addCount(sum[i], 1);
    };
    long long ans = -1;
    if (sum[n] == 0) {
      if (getCount(x) != 0 || x == 0)
        ans = -1;
      else
        ans = 0;
    } else {
      ans = 0;
      for (int i = 1; i <= n; i++) {
        if (!vis.count(sum[i])) {
          vis[sum[i]] = 1;
          int need = x - sum[i];
          if (sameSign(sum[n], need) && ((need % sum[n]) == 0))
            ans += (long long)count[sum[i]];
        }
      };
      if (x == 0) ans++;
    }
    printf("%lld\n", ans);
  }
  return 0;
}
