#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, x, i, p, a, b, flag = 0, ans = 0;
    cin >> n >> x;
    string s;
    cin >> s;
    long long int dp[n + 1];
    dp[0] = 0;
    for (i = 0; i < n; i++) {
      if (s[i] == '0') {
        dp[i + 1] = dp[i] + 1;
      } else {
        dp[i + 1] = dp[i] - 1;
      }
    }
    p = dp[n];
    if (p == 0) {
      for (i = 0; i < n; i++) {
        if (dp[i] == x) {
          flag = 1;
          i = n;
        }
      }
      if (flag == 1) {
        cout << -1 << endl;
      } else {
        cout << 0 << endl;
      }
    } else {
      for (i = 0; i < n; i++) {
        a = x - dp[i];
        if (abs(a) % p == 0 && a * p >= 0) {
          ans++;
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
