#include <bits/stdc++.h>
using namespace std;
char s[100000 + 50];
int T, x, n;
;
int num[100000 + 50];
int main() {
  scanf("%d", &T);
  for (int cl = 1; cl <= T; cl++) {
    scanf("%d %d", &n, &x);
    scanf("%s", s);
    for (int i = 0; i < n; i++) {
      if (s[i] == '0')
        num[i + 1] = num[i] + 1;
      else
        num[i + 1] = num[i] - 1;
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (num[i] == x)
        cnt++;
      else {
        if (num[i] < x && num[n] > 0 && (x - num[i]) % num[n] == 0)
          cnt++;
        else {
          if (num[i] > x && num[n] < 0 && (num[i] - x) % (0 - num[n]) == 0)
            cnt++;
        }
      }
    }
    if (num[n] == 0 && cnt != 0)
      printf("-1\n");
    else {
      printf("%d\n", cnt);
    }
  }
  return 0;
}
