#include <bits/stdc++.h>
#pragma optimize("O3")
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;
const int base = 2e5 + 1;
const int MAX = 1e7 + 1;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 1000;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n, x;
    string s;
    cin >> n >> x >> s;
    long long b = 0, a = 0;
    for (long long i = (0); i < (n); ++i) {
      if (s[i] == '0')
        b++;
      else
        b--;
    }
    if (b == 0) {
      bool was = (b == x);
      for (long long i = (0); i < (n); ++i) {
        if (a == x) was = 1;
        if (s[i] == '0')
          a++;
        else
          a--;
      }
      if (was)
        cout << -1 << '\n';
      else
        cout << 0 << '\n';
      continue;
    }
    int cnt = 0;
    for (long long i = (0); i < (n); ++i) {
      if ((x - a) % b == 0) {
        long long k = (x - a) / b;
        if (k >= 0) cnt++;
      }
      if (s[i] == '0')
        a++;
      else
        a--;
    }
    cout << cnt << '\n';
  }
  return 0;
}
