#include <bits/stdc++.h>
using namespace std;
long long modexp(long long n, long long m) {
  if (m == 0)
    return 1;
  else if (m == 1)
    return n;
  else {
    long long p = modexp(n, m / 2);
    if (m % 2 == 1)
      return (((p * p) % 1000000007) * n) % 1000000007;
    else
      return (p * p) % 1000000007;
  }
}
long long exp(long long n, long long m) {
  if (m == 0) return 1;
  if (m == 1) return n;
  long long p = exp(n, m / 2);
  if (m % 2 == 1)
    return p * p * n;
  else
    return p * p;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long inv(long long n) { return modexp(n, 1000000007 - 2); }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long factorial(long long fact[], long long n) {
  fact[0] = 1;
  fact[1] = 1;
  long long prod = 1, i;
  for (i = 2; i < n + 1; i++) {
    prod = (prod * i) % 1000000007;
    fact[i] = prod;
  }
  return prod;
}
bool comparator(pair<long long, long long> p1, pair<long long, long long> p2) {
  return p1.second > p2.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, i, j, k, m, t, T, x;
  cin >> T;
  while (T--) {
    string s;
    cin >> n >> x >> s;
    vector<long long> pre(n + 1);
    pre[0] = 0;
    long long c0 = 0, c1 = 0;
    for (i = 0; i < n; i++) {
      if (s[i] == '0')
        c0++;
      else
        c1++;
      pre[i + 1] = c0 - c1;
    }
    long long count = 0;
    bool flag = false;
    if (x == 0) count++;
    for (i = 1; i < n + 1; i++) {
      if (pre[n] != 0) {
        if ((x - pre[i]) % pre[n] == 0 && (x - pre[i]) / pre[n] >= 0) count++;
      } else {
        if (x - pre[i] == 0) {
          flag = true;
          break;
        }
      }
    }
    if (flag)
      cout << -1 << endl;
    else
      cout << count << endl;
  }
  return 0;
}
