#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  } else
    return false;
}
template <class T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  } else
    return false;
}
void main2() {
  long long n, x;
  cin >> n >> x;
  string s;
  cin >> s;
  vector<long long> c(n + 1, 0);
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      c[i + 1] = c[i] + 1;
    } else {
      c[i + 1] = c[i] - 1;
    }
  }
  int ans = 0;
  if (c[n] == 0) {
    for (int i = 0; i < n; i++) {
      if (c[i] == x) ans++;
    }
    if (ans) {
      cout << -1 << '\n';
    } else {
      cout << 0 << '\n';
    }
    return;
  }
  for (int i = 0; i < n; i++) {
    if ((x - c[i]) % c[n] == 0) {
      if ((x - c[i]) / c[n] >= 0) ans++;
    }
  }
  cout << ans << '\n';
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int t = 1;
  cin >> t;
  for (int _ = 0; _ < t; _++) main2();
}
