#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
char s[maxn];
int p[maxn];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n >> x;
    cin >> s;
    p[0] = 0;
    for (int i = 1; i <= n; i++) {
      if (s[i - 1] == '0')
        p[i] = p[i - 1] + 1;
      else
        p[i] = p[i - 1] - 1;
    }
    int anst = p[n], ans = 0;
    if (x == 0) ans++;
    if (anst == 0) {
      for (int i = 1; i <= n; i++) {
        if (p[i] == x) ans++;
      }
      if (ans > 0)
        cout << "-1" << endl;
      else
        cout << "0" << endl;
    } else {
      for (int i = 1; i <= n; i++) {
        int num = x - p[i];
        if (num % anst != 0 || num / anst < 0) {
          continue;
        }
        ans++;
      }
      cout << ans << endl;
    }
  }
  return 0;
}
