#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T;
  cin >> T;
  while (T--) {
    long long int n, x;
    string s;
    cin >> n >> x >> s;
    long long int bal = 0;
    map<long long int, long long int> counts;
    for (auto c : s) {
      counts[bal]++;
      if (c == '0')
        bal++;
      else
        bal--;
    }
    if (bal == 0) {
      if (counts[x])
        cout << -1 << endl;
      else
        cout << 0 << endl;
    } else {
      long long int ans = 0;
      for (auto p : counts) {
        if (((x - p.first) % bal) || (x > p.first && bal < 0) ||
            (x < p.first && bal > 0))
          continue;
        ans += p.second;
      }
      cout << ans << endl;
    }
  }
}
