#include <bits/stdc++.h>
using namespace std;
char s[100005];
int pre[100005];
map<int, int> pmap;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, x;
    scanf("%d%d%s", &n, &x, s);
    pmap.clear();
    int pref = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '0')
        pref++;
      else
        pref--;
      pre[i] = pref;
      pmap[pre[i]]++;
    }
    if (pref == 0 && pmap.find(x) != pmap.end())
      printf("-1\n");
    else {
      long long ans = 0;
      int rpre = pmap.rbegin()->first;
      int lpre = pmap.begin()->first;
      if (x < lpre) {
        if (pref < 0) {
          int k = (x - lpre) / pref;
          if ((lpre - x) % (-pref)) k++;
          int focus = x - (k * pref);
          while (focus >= lpre && focus <= rpre) {
            ans += pmap[focus];
            focus -= pref;
          }
        }
      } else if (x > rpre) {
        if (pref > 0) {
          int k = (x - rpre) / pref;
          if ((x - rpre) % pref) k++;
          int focus = x - (k * pref);
          while (focus >= lpre && focus <= rpre) {
            ans += pmap[focus];
            focus -= pref;
          }
        }
      } else if (pref != 0) {
        int focus = x;
        while (focus >= lpre && focus <= rpre) {
          ans += pmap[focus];
          focus -= pref;
        }
      }
      if (x == 0) ans++;
      printf("%lld\n", ans);
    }
  }
  return 0;
}
