#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7;
const int mod = 1e9 + 7;
void solve1() {
  int n, x;
  string s;
  cin >> n >> x >> s;
  int cnt = 0;
  int ans = (x == 0);
  for (int i = 0; i < n; i++) {
    if (s[i] == '0')
      cnt += 1;
    else
      cnt -= 1;
    if (cnt == x) ans += 1;
  }
  if (ans > 0 && cnt == 0) {
    cout << "-1\n";
    return;
  }
  if (cnt == 0) {
    cout << "0\n";
    return;
  }
  ans = (x == 0);
  int cnt1 = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0')
      cnt1 += 1;
    else
      cnt1 -= 1;
    int y = x - cnt1;
    if ((y >= 0 && cnt > 0) || (y <= 0 && cnt < 0)) {
      if (abs(y) % abs(cnt) == 0) ans += 1;
    }
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  srand(time(0));
  int cghf = 1;
  cin >> cghf;
  while (cghf--) {
    solve1();
  }
}
