#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 * 1000 + 10;
int t, n, x, dp[maxn], mn, mx, ans;
string s;
int main() {
  cin >> t;
  for (int z = 0; z < t; z++) {
    mn = mx = ans = 0;
    cin >> n >> x >> s;
    for (int i = 0; i < n; i++) {
      dp[i + 1] = dp[i];
      if (s[i] == '0')
        dp[i + 1]++;
      else
        dp[i + 1]--;
      mn = min(mn, dp[i + 1]);
      mx = max(mx, dp[i + 1]);
    }
    if (dp[n] == 0) {
      if (mn <= x && x <= mx)
        cout << -1 << endl;
      else
        cout << 0 << endl;
    } else {
      for (int i = 0; i < n; i++) {
        if ((x - dp[i]) % dp[n] == 0 && (long long)(x - dp[i]) * dp[n] >= 0)
          ans++;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
