#include <bits/stdc++.h>
using namespace std;
mt19937 rnd;
const int N = 1e5 + 10;
long long pref[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long n, x;
    cin >> n >> x;
    string s;
    cin >> s;
    s = '*' + s;
    for (int i = 1; i <= n; i++) {
      pref[i] = pref[i - 1];
      if (s[i] == '1')
        pref[i]--;
      else
        pref[i]++;
    }
    bool inf = 0;
    for (int i = 1; i <= n; i++) {
      if (pref[i] == x) {
        inf = 1;
      }
    }
    if (pref[n] != 0) {
      inf = 0;
    }
    if (inf) {
      cout << "-1\n";
      continue;
    }
    int ans = 0;
    if (x == 0) ans++;
    if (pref[n] == 0) {
      for (int i = 1; i <= n; i++) {
        if (pref[i] == x) {
          ans++;
        }
      }
    } else {
      for (int i = 1; i <= n; i++) {
        if ((pref[i] - x) % pref[n] == 0) {
          if (pref[n] > 0 && pref[i] <= x) {
            ans++;
          }
          if (pref[n] < 0 && pref[i] >= x) {
            ans++;
          }
          if (pref[n] == 0 && pref[i] == x) {
            ans++;
          }
        }
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
