#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, x, i, j, k, l;
    cin >> n >> x;
    string s;
    cin >> s;
    k = 0;
    for (long long int i = 0; i <= n - 1; i++)
      k += (s[i] == '0') - (s[i] == '1');
    long long int ans = 0;
    l = 0;
    for (long long int i = 0; i <= n - 1; i++) {
      if (k == 0) {
        if (l == x) {
          ans = -1;
          break;
        }
      } else {
        j = x - l;
        if ((j % k) == 0 && j * k >= 0) ans++;
      }
      l += (s[i] == '0') - (s[i] == '1');
    }
    cout << ans << '\n';
  }
  return 0;
}
