#include <bits/stdc++.h>
using namespace std;
char s[100010];
int b[100010];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, x;
    scanf("%d%d%s", &n, &x, s);
    int cnt0 = 0, cnt1 = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '0')
        cnt0++;
      else
        cnt1++;
      b[i] = cnt0 - cnt1;
    }
    if (b[n - 1] == 0) {
      int ans = 0;
      if (x == 0) ans = -1;
      for (int i = 0; i < n; i++) {
        if (b[i] == x) ans = -1;
      }
      printf("%d\n", ans);
      continue;
    }
    int ans = 0;
    if (x == 0) ans++;
    for (int i = 0; i < n; i++) {
      if ((x - b[i]) % b[n - 1] == 0 and (x - b[i]) / b[n - 1] >= 0) {
        ans++;
      }
    }
    printf("%d\n", ans);
  }
}
