#include <bits/stdc++.h>
using namespace std;
const long long INF = 571795717957;
const long long MOD = 1000000007;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long y = 0;
  cin >> y;
  while (y) {
    y--;
    long long n, x;
    cin >> n >> x;
    string binnum;
    cin >> binnum;
    vector<long long> pref = {};
    if (binnum[0] == '1') {
      pref.push_back(-1);
    } else {
      pref.push_back(1);
    }
    for (long long i = 1; i < n; i++) {
      if (binnum[i] == '1') {
        pref.push_back(pref.back() - 1);
      } else {
        pref.push_back(pref.back() + 1);
      }
    }
    long long f = 0;
    long long ending = pref.back();
    long long ans = 0;
    for (auto el : pref) {
      if (ending && (!((x - el) % ending)) && (x - el) / ending >= 0) {
        ans += 1;
      } else {
        if ((!ending) && (x == el) && (!f)) {
          cout << -1 << endl;
          f = 1;
        }
      }
    }
    if (!f) {
      if (x == 0) {
        cout << ans + 1 << endl;
      } else {
        cout << ans << endl;
      }
    }
  }
}
