#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 15;
char S[MAXN];
long long D[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    long long N, X;
    cin >> N >> X >> S;
    long long C[2] = {};
    for (int i = 0; i < N; ++i) {
      ++C[S[i] - '0'];
      D[i] = C[0] - C[1];
    }
    long long x = C[0] - C[1];
    int ans = X == 0 ? 1 : 0;
    if (x == 0) {
      for (int i = 0; i < N; ++i)
        if (X - D[i] == 0) ++ans;
      if (ans > 0) ans = -1;
      cout << ans << endl;
    } else {
      for (int i = 0; i < N; ++i) {
        if (((X - D[i]) >= 0 && x > 0) || ((X - D[i]) <= 0 && x < 0)) {
          if ((X - D[i]) % x == 0) ++ans;
        }
      }
      cout << ans << endl;
    }
  }
  return 0;
}
