#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  int n;
  int t;
  cin >> t;
  int ans = 0;
  while (t--) {
    int m;
    cin >> n >> m;
    string s;
    ans = 0;
    cin >> s;
    int c1 = 0, c0 = 0;
    for (auto it : s) {
      if (it == '0')
        c0++;
      else
        c1++;
    }
    if (c0 == c1) {
      c1 = 0;
      c0 = 0;
      for (auto it : s) {
        if (it == '0')
          c0++;
        else
          c1++;
        if (c0 - c1 == m) {
          ans++;
        }
      }
      if (ans) {
        cout << -1 << endl;
      } else {
        cout << 0 << endl;
      }
      continue;
    }
    long long int x = c0 - c1;
    c0 = 0;
    c1 = 0;
    if (m == 0) ans++;
    for (auto it : s) {
      if (it == '1')
        c1++;
      else
        c0++;
      int dd = c0 - c1;
      long long int nd = m - dd;
      if (nd % x == 0 and nd * x >= 0) {
        ans++;
      }
    }
    cout << ans << endl;
  }
}
