#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  ;
  int t;
  cin >> t;
  ;
  while (t--) {
    int n, x;
    string s;
    cin >> n >> x >> s;
    int z = (int)count(s.begin(), s.end(), '0');
    int count = 2 * z - n;
    int b = 0, ans = 0;
    for (int i = 0; i < n; i++) {
      if (count == 0 && b == x) {
        ans = -1;
        break;
      } else if (count != 0 && abs(x - b) % abs(count) == 0 &&
                 (x - b) / count >= 0)
        ans++;
      if (s[i] == '0')
        b++;
      else
        b--;
    }
    cout << ans << endl;
  }
  return 0;
}
