#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const double EPS = 1e-10;
const double PI = acos(-1);
class BInfinitePrefixes {
 public:
  void solve(std::istream& in, std::ostream& out) {
    ios_base::sync_with_stdio(false);
    in.tie(nullptr), out.tie(nullptr);
    int tt;
    in >> tt;
    while (tt--) {
      int N, X;
      in >> N >> X;
      string S;
      in >> S;
      int bal = 0;
      map<int, int> mp;
      for (auto c : S) {
        if (c == '0')
          ++bal;
        else
          --bal;
        mp[bal]++;
      }
      if (bal == 0) {
        if (mp.count(X))
          out << "-1\n";
        else
          out << "0\n";
      } else if (bal > 0) {
        int ans = 0;
        for (auto p : mp) {
          if (X >= p.first and
              (X % bal + bal) % bal == (p.first % bal + bal) % bal)
            ans += p.second;
        }
        if (X == 0) ++ans;
        out << ans << '\n';
      } else {
        int ans = 0;
        X *= -1;
        bal *= -1;
        for (auto p : mp) {
          int pf = p.first * (-1);
          if (X >= pf and (X % bal + bal) % bal == (pf % bal + bal) % bal)
            ans += p.second;
        }
        if (X == 0) ++ans;
        out << ans << '\n';
      }
    }
  }
};
int main() {
  BInfinitePrefixes solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
