#include <bits/stdc++.h>
using namespace std;
template <typename T>
void stmin(T &a, T b) {
  if (a > b) a = b;
}
template <typename T>
void stmax(T &a, T b) {
  if (a < b) a = b;
}
long long int solve() {
  long long int n, x;
  cin >> n >> x;
  string s;
  cin >> s;
  long long int c0 = 0, c1 = 0;
  std::map<long long int, long long int> mp;
  for (long long int i = 0; i < n; i++) {
    mp[c0 - c1]++;
    if (s[i] == '0') {
      c0++;
    } else {
      c1++;
    }
  }
  long long int t = c0 - c1;
  if (t == 0) {
    if (mp[x]) {
      cout << -1 << endl;
    } else {
      cout << 0 << endl;
    }
    return 0;
  }
  long long int ans = 0;
  for (auto &x1 : mp) {
    long long int t1 = x - x1.first;
    if ((t1) % t == 0 && t * t1 >= 0) {
      ans += x1.second;
    }
  }
  cout << ans << endl;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int test = 1, c = 1;
  cin >> test;
  while (test--) {
    solve();
  }
}
