#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
  int res = 0;
  while (n && ++res) n -= n & (-n);
  return res;
}
template <class T>
void chmax(T& a, const T& b) {
  a = max(a, b);
}
template <class T>
void chmin(T& a, const T& b) {
  a = min(a, b);
}
int main() {
  long long t, n, x, i, cnt, size, bal, save;
  vector<long long> A;
  string S;
  cin >> t;
  while (t--) {
    cnt = 0;
    save = 0;
    A.clear();
    cin >> n >> x;
    cin >> S;
    size = S.size();
    for (i = 0; i < size; i++) {
      if (S[i] == '1')
        cnt--;
      else
        cnt++;
      A.push_back(cnt);
    }
    bal = *(A.end() - 1);
    if (bal == 0) {
      if (count(A.begin(), A.end(), x) == 0) {
        cout << 0 << endl;
        continue;
      }
      cout << -1 << endl;
      continue;
    }
    if (x == 0) {
      save++;
    }
    for (i = 0; i < A.size(); i++) {
      if ((x - A[i]) % bal == 0 && ((x - A[i]) / bal) >= 0) {
        save++;
      }
    }
    cout << save << endl;
  }
  return 0;
}
