#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const long long N = 2e5 + 1;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  ;
  while (t--) {
    long long n, x;
    string str;
    cin >> n >> x >> str;
    map<long long, long long> mp;
    long long sum = 0;
    for (char ch : str) {
      if (ch == '0')
        sum++;
      else
        sum--;
      mp[sum]++;
    }
    if (!sum && mp[x]) {
      cout << -1 << '\n';
      continue;
    } else if (!sum) {
      cout << 0 << '\n';
      continue;
    }
    long long ans = 0;
    for (pair<long long, long long> i : mp) {
      long long y = i.first, z = i.second;
      if (((y % (abs(sum)) + sum) % sum) == ((x % (abs(sum)) + sum) % sum)) {
        if (sum > 0 && (x - y) >= 0)
          ans += z;
        else if (sum < 0 && (x - y) <= 0)
          ans += z;
      }
    }
    if (!x)
      cout << ans + 1 << '\n';
    else
      cout << ans << '\n';
  }
}
