#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
const long long maxn = (long long)1e6 + 5;
const long long mod = 1000000007;
const long long inf = 0x3f3f3f3f;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    unordered_map<long long, long long> mp;
    long long n, x;
    cin >> n >> x;
    string s;
    cin >> s;
    long long balmax = -1e6, balmin = 1e6, bal = 0;
    for (auto &i : s) {
      if (i == '0')
        ++bal;
      else
        --bal;
      ++mp[bal];
      balmax = max(balmax, bal);
      balmin = min(balmin, bal);
    }
    if (bal == 0) {
      if (x >= balmin && x <= balmax)
        cout << -1 << '\n';
      else
        cout << 0 << '\n';
      continue;
    }
    long long balt = 0;
    long long ans = 0;
    if (x == 0) ++ans;
    for (auto &i : s) {
      if (i == '0')
        ++balt;
      else
        --balt;
      if ((x - balt) * bal >= 0 && (x - balt) % bal == 0) ++ans;
    }
    cout << ans << '\n';
  }
  return 0;
}
