#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long k) {
  if (k <= 1) {
    return false;
  }
  if (k == 2) {
    return true;
  }
  if (k % 2 == 0) {
    return false;
  }
  long long i = 3;
  while (i * i <= k) {
    if (k % i == 0) {
      return false;
    }
    i += 2;
  }
  return true;
}
long long modexp(long long x, long long n, long long m) {
  if (n == 0) return 1 % m;
  long long u = modexp(x, n / 2, m);
  u = (u * u) % m;
  if (n % 2 == 1) u = (u * x) % m;
  return u;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long x1, y1;
  long long d = exgcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return d;
}
long long modinv(long long x, long long mod) { return modexp(x, mod - 2, mod); }
const int Nx = 1e6 + 5;
long long fac[Nx];
void fact() {
  fac[0] = 1;
  for (int i = 1; i < Nx; i++) {
    fac[i] = (fac[i - 1] * i) % 998244353;
  }
  return;
}
long long nCr(long long a, long long b, long long mod) {
  return ((fac[a] * modinv(fac[b], mod)) % mod * modinv(fac[a - b], mod)) % mod;
}
long long N = 1e5 + 4;
vector<bool> is_prime(N + 1, true);
void validateprime(long long n) {
  is_prime[0] = is_prime[1] = false;
  for (long long i = 2; i <= n; i++) {
    if (is_prime[i] && (long long)i * i <= n) {
      for (long long j = i * i; j <= n; j += i) is_prime[j] = false;
    }
  }
}
void dfs(long long s, vector<bool> &v, vector<long long> adj[]) {
  if (v[s]) return;
  v[s] = true;
  cout << s + 1 << " ";
  for (auto u : adj[s]) {
    dfs(u, v, adj);
  }
}
void bfs(vector<pair<long long, long long> > &dis, vector<long long> adj[],
         long long s, vector<long long> &parent) {
  dis[s].first = 0;
  parent[s] = -1;
  queue<long long> q;
  q.push(s);
  while (!q.empty()) {
    long long z = q.front();
    q.pop();
    dis[z].second = 0;
    for (long long v : adj[z]) {
      if (dis[v].first == -1) {
        dis[z].second = -1;
        q.push(v);
        dis[v].first = dis[z].first + 1;
        parent[v] = z;
      }
    }
  }
}
vector<long long> primes;
void storePrime(long long n) {
  validateprime(n);
  for (long long i = 0; i < n; i++) {
    if (is_prime[i + 1]) {
      primes.push_back(i + 1);
    }
  }
}
void srihrg() {
  long long n, x;
  cin >> n >> x;
  string s;
  cin >> s;
  long long bn = 0;
  long long cn = 0;
  long long yu = 0;
  for (long long i = 0; i < n; i++) {
    if (s[i] == '0') {
      yu++;
    }
  }
  yu = 2 * yu - n;
  bool k = 0;
  for (long long i = 0; i < n; i++) {
    if (yu == 0) {
      if (bn == x) k = 1;
    } else {
      if ((x - bn) % abs(yu) == 0) {
        if ((x - bn) * yu >= 0) {
          cn++;
        }
      }
    }
    if (s[i] == '0')
      bn++;
    else
      bn--;
  }
  if (k) {
    cout << -1;
  } else {
    cout << cn;
  }
}
int main(int argc, const char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long query = 1;
  cin >> query;
  for (long long queryit = 1; queryit <= query; queryit++) {
    srihrg();
    cout << endl;
  }
  return 0;
}
