#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    long long bf = 0;
    vector<long long> v;
    for (char c : s) {
      if (c == '0')
        bf++;
      else
        bf--;
      v.emplace_back(bf);
    }
    if (bf == 0) {
      bool ans = 1;
      for (long long x : v) {
        if (k == x || k == 0) {
          ans = 0;
          break;
        }
      }
      ans ? cout << 0 : cout << -1;
      cout << "\n";
    } else {
      long long cnt = ((k == 0) ? 1 : 0);
      for (long long x : v) {
        long long diff = k - x;
        if ((diff >= 0 && bf > 0) || (diff <= 0 && bf < 0)) {
          if ((k - x) % bf == 0) ++cnt;
        }
      }
      cout << cnt << "\n";
    }
  }
}
