#include <bits/stdc++.h>
using namespace std;
void foobar() {
  long long int n, x;
  cin >> n >> x;
  string str;
  cin >> str;
  long long int i;
  vector<long long int> vec(n);
  long long int zero = 0, one = 0;
  for (i = 0; i < n; ++i) {
    if (str[i] == '0') {
      zero++;
    } else {
      one++;
    }
    vec[i] = zero - one;
  }
  long long int d = vec[n - 1];
  long long int c = 0;
  if (x == 0) {
    c++;
  }
  for (i = 0; i < n; ++i) {
    if (d == 0) {
      if (vec[i] == x) {
        cout << "-1" << endl;
        return;
      }
      continue;
    }
    long long int slam = x - vec[i];
    if (slam % d == 0) {
      long long int nn = slam / d + 1;
      if (nn > 0) {
        c++;
      }
    }
  }
  cout << c << endl;
}
int main() {
  long long int test;
  cin >> test;
  while (test--) foobar();
}
