#include <bits/stdc++.h>
using namespace std;
int sign(long long x) {
  if (x < 0) return -1;
  if (x > 0) return 1;
  return 0;
}
int solve(int N, long long X, const string& S) {
  vector<int> PS(N + 1);
  for (int i = (1), _b = (N); i <= _b; ++i) {
    PS[i] = PS[i - 1] + (S[i - 1] == '0' ? +1 : -1);
  }
  if (PS[N] == 0) {
    for (int i = (1), _b = (N); i <= _b; ++i)
      if (PS[i] == X) return -1;
    return 0;
  }
  int res = 0;
  for (int i = (1), _b = (N); i <= _b; ++i) {
    long long dif = X - PS[i];
    if ((dif % PS[N]) == 0) {
      if (dif == 0 || sign(dif) == sign(PS[N])) ++res;
    }
  }
  if (X == 0) ++res;
  return res;
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int TC;
  cin >> TC;
  for (int tc = (1), _b = (TC); tc <= _b; ++tc) {
    int N, X;
    cin >> N >> X;
    string S;
    cin >> S;
    int res = solve(N, X, S);
    cout << res << '\n';
  }
  return 0;
}
