#include <bits/stdc++.h>
using namespace std;
const long long mod = (1 ? 1e9 + 7 : 998244353);
const int N = 2e5 + 2;
const int M = 2e7 + 2;
const int inf = 2e9;
const long long linf = 1e18;
int f(char s) {
  if (s == '0') return 1;
  return -1;
}
void solve() {
  int n, x;
  string s;
  cin >> n >> x >> s;
  vector<int> p(n, 0);
  p[0] = f(s[0]);
  for (int i = 1; i < n; i++) p[i] = p[i - 1] + f(s[i]);
  if (!p[n - 1]) {
    int ans = 0;
    for (int i = 0; i < n; i++)
      if (p[i] == x) ans = -1;
    cout << ans << '\n';
    return;
  }
  int ans = !x;
  for (int i = 0; i < n; i++) {
    if (p[n - 1] > 0 && (x - p[i]) % p[n - 1] == 0 && x - p[i] >= 0) ans++;
    if (p[n - 1] < 0 && (p[i] - x) % p[n - 1] == 0 && p[i] - x >= 0) ans++;
  }
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cerr.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
  return 0;
}
