#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int n, x;
string s;
int pre[N + 10];
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> x;
    cin >> s;
    int len = s.size();
    pre[0] = 0;
    for (int i = 0; i < len; i++) {
      if (s[i] == '0')
        pre[i + 1] = pre[i] + 1;
      else
        pre[i + 1] = pre[i] - 1;
    }
    int delta = pre[len];
    bool inf = 0;
    long long ans = 0;
    for (int i = 0; i <= len; i++) {
      if (pre[i] == x) ans++;
      if (pre[i] == x && delta == 0) inf = 1;
      if (i != 0 && pre[i] < x && delta > 0 && (x - pre[i]) % delta == 0) ans++;
      if (i != 0 && pre[i] > x && delta < 0 && (pre[i] - x) % (-delta) == 0)
        ans++;
    }
    if (inf)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
