#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, x;
  cin >> n >> x;
  string s;
  cin >> s;
  long long int arr[n];
  memset(arr, 0, sizeof(arr));
  if (s[0] == '0')
    arr[0] = 1;
  else if (s[0] == '1')
    arr[0] = -1;
  for (long long int i = 1; i < n; i++) {
    arr[i] = arr[i - 1];
    if (s[i] == '0') {
      arr[i] += 1;
    } else {
      arr[i] += -1;
    }
  }
  long long int k = arr[n - 1];
  long long int cnt = 0;
  long long int found = 0;
  if (k == 0) {
    for (long long int i = 0; i < n; i++) {
      if (arr[i] == x) {
        cout << -1;
        return;
      }
    }
  } else {
    for (long long int i = 0; i < n; i++) {
      if ((x - arr[i]) % k == 0 && (x - arr[i]) / k >= 0) {
        cnt++;
        found = 1;
      }
    }
  }
  if (x == 0) {
    cout << cnt + 1;
  } else {
    cout << cnt;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int T = 1;
  cin >> T;
  while (T--) {
    solve();
    cout << endl;
  }
  return 0;
}
