#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  for (int _ = 0; _ < t; ++_) {
    int n, x;
    cin >> n >> x;
    string s;
    cin >> s;
    int bal = 0;
    for (auto& c : s) {
      bal += (c == '0' ? 1 : -1);
    }
    int cur_b = 0;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      if (bal == 0 && cur_b == x) {
        cout << -1 << endl;
        goto en;
      } else {
        if (bal != 0 && (x - cur_b) % bal == 0 && (x - cur_b) / bal >= 0) {
          ans++;
        }
      }
      cur_b += (s[i] == '0' ? 1 : -1);
    }
    cout << ans << endl;
  en:;
  }
}
