#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int t;
  cin >> t;
  for (ll _ = 0, _Len = (t); _ < _Len; ++_) {
    ll n, x;
    string bit_s;
    cin >> n >> x >> bit_s;
    vector<ll> acc(n);
    map<ll, ll> cnt;
    acc[0] = (bit_s[0] == '0' ? 1 : -1);
    cnt[acc[0]]++;
    for (ll i = 1, iLen = (n); i < iLen; ++i) {
      acc[i] = acc[i - 1] + (bit_s[i] == '0' ? 1 : -1);
      cnt[acc[i]]++;
    }
    if (acc[n - 1] == 0) {
      cout << (cnt[x] > 0 ? -1 : (x == 0 ? 1 : 0)) << "\n";
      continue;
    }
    ll ans = (x == 0 ? 1 : 0), m = acc[n - 1];
    for (auto &[c, v] : cnt) {
      if ((x - c) % m == 0 && (x - c) / m >= 0) ans += v;
    }
    cout << ans << "\n";
  }
}
