#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    string s;
    cin >> n >> x >> s;
    int a[n];
    for (int i = 0; i < n; i++)
      a[i] = (i ? a[i - 1] : 0) + (s[i] == '0' ? 1 : -1);
    int d = a[n - 1], res = (x ? 0 : 1);
    for (int i = 0; i < n; i++) {
      if (d == 0 && a[i] == x) {
        res = -1;
        break;
      } else if (d) {
        double k = double(x - a[i]) / d + 1;
        if (int(k) == k && k > 0) res++;
      }
    }
    cout << res << endl;
  }
  return 0;
}
