#include <bits/stdc++.h>
#pragma GCC optimizer(2)
using namespace std;
const int INF = 0x3f3f3f3f;
const int M = 40005;
const int N = 95;
int main() {
  long long t, n, x, a[100100], len, flag;
  cin >> t;
  char s[100010];
  while (t--) {
    cin >> n >> x;
    long long cnt0, cnt1, cnt;
    scanf("%s", s);
    len = strlen(s);
    cnt1 = cnt0 = cnt = flag = 0;
    a[0] = 0;
    for (int i = 1; i <= len; i++) {
      if (s[i - 1] == '0')
        cnt0++;
      else
        cnt1++;
      a[i] = cnt0 - cnt1;
      if (a[i] == x) flag = 1;
    }
    if ((!a[len] && flag)) {
      cout << "-1" << endl;
      continue;
    }
    long long tmp;
    if (!x) cnt++;
    for (int i = 1; i <= len; i++) {
      tmp = x - a[i];
      if (!tmp) cnt++;
      if (a[len] && !(tmp % a[len]) && (a[len] * tmp > 0)) cnt++;
    }
    cout << cnt << endl;
  }
  return 0;
}
