#include <bits/stdc++.h>
using namespace std;
char s[300010];
int sum[300010];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    scanf("%d%d", &n, &x);
    scanf("%s", s + 1);
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      sum[i] = sum[i - 1] + (s[i] == '0' ? 1 : -1);
      if (sum[i] == x) ans++;
    }
    if (sum[n] == 0 && ans > 0) {
      cout << -1 << endl;
      continue;
    } else if (sum[n] == 0 && ans == 0) {
      cout << 0 << endl;
      continue;
    }
    ans = 0;
    for (int i = 1; i <= n; i++) {
      if ((x - sum[i]) % sum[n] == 0 && (x - sum[i]) / sum[n] >= 0) ans++;
    }
    if (x == 0) ans++;
    cout << ans << endl;
  }
  return 0;
}
