#include <bits/stdc++.h>
using namespace std;
int main() {
  long long T;
  cin >> T;
  while (T--) {
    long long n, x;
    cin >> n >> x;
    string ss;
    cin >> ss;
    vector<long long> v;
    v.push_back(0);
    long long o = 0, z = 0;
    for (long long i = 0; i < n; i++) {
      if (ss[i] == '0')
        z++;
      else
        o++;
      v.push_back(z - o);
    }
    long long s = v[n];
    long long ans = 0;
    bool ch = true;
    for (long long i = 0; i < n; i++) {
      long long a = x - v[i];
      if (a == 0 and s == 0) {
        ch = false;
        break;
      }
      if (s != 0 and a % s == 0 and (a / s) >= 0) {
        ans++;
      }
    }
    if (!ch) ans = -1;
    cout << ans << endl;
  }
}
