#include <bits/stdc++.h>
using namespace std;
int t, n, x;
string s;
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> x;
    cin >> s;
    int ans = 0, val = 0;
    vector<long long> balance(n + 1, 0);
    for (int i = 0; i < n; i++) {
      balance[i] = val;
      if (s[i] == '0') {
        val++;
      } else
        val--;
      if (val == x) ans++;
    }
    if (val == 0 && ans != 0)
      cout << -1 << endl;
    else if (val == 0 && ans == 0)
      cout << 0 << endl;
    else {
      ans = 0;
      for (int i = 0; i < n; i++) {
        if ((x - balance[i]) % val == 0 && (x - balance[i]) * val >= 0) ans++;
      }
      cout << ans << endl;
    }
  }
}
