#include <bits/stdc++.h>
using namespace std;
int sum[100005], d[100005];
int main() {
  int t, n, x, ans;
  char s[100005];
  cin >> t;
  while (t--) {
    cin >> n >> x;
    cin.get();
    cin.getline(s + 1, 100002);
    ans = 0;
    for (int i = 1; i <= n; i++) {
      sum[i] = sum[i - 1] + (int)(s[i] - '0');
      d[i] = i - 2 * sum[i];
    }
    if (d[n] == 0) {
      for (int i = 1; i <= n; i++)
        if (d[i] == x) ans = -1;
    } else {
      if (x == 0) ans++;
      for (int i = 1; i <= n; i++)
        if ((x - d[i]) % d[n] == 0) {
          int k = (x - d[i]) / d[n];
          if (k >= 0) ans++;
        }
    }
    cout << ans << '\n';
  }
  return 0;
}
