#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int main() {
  int test = 1;
  scanf("%d", &test);
  while (test--) {
    int n, x, cnt = 0;
    map<int, int> f;
    scanf("%d %d", &n, &x);
    string s;
    cin >> s;
    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '1') {
        cnt--;
      } else {
        cnt++;
      }
      f[cnt]++;
    }
    if (cnt == 0) {
      if (cnt == x) {
        printf("-1\n");
      } else if (f[x]) {
        printf("-1\n");
      } else {
        printf("0\n");
      }
      continue;
    }
    long long ans = 0;
    if (x == 0) {
      ans++;
    }
    for (auto it = f.begin(); it != f.end(); it++) {
      long long tot = (x - (it->first)) / cnt;
      if (tot >= 0 && abs((x - (it->first))) % abs(cnt) == 0) {
        ans += it->second;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
