#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n >> x;
    string s;
    cin >> s;
    int prefix[n + 1];
    prefix[0] = 0;
    int one = 0, zero = 0;
    bool flag = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '1')
        one++;
      else
        zero++;
      prefix[i + 1] = (zero - one);
      if (prefix[i + 1] == x) {
        flag = 1;
      }
    }
    int diff = (zero - one);
    if (flag && diff == 0) {
      cout << -1 << endl;
      continue;
    } else if (diff == 0) {
      cout << 0 << endl;
      continue;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (abs(x - prefix[i]) % abs(diff) == 0) {
        if ((x - prefix[i]) / diff >= 0) ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
