#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
const int O = 1e5;
const double PI = acos(-1.0);
const double E = 2.718281828459;
const double eps = 1e-7;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n, x;
    cin >> n >> x;
    string s;
    cin >> s;
    int cnt[maxn];
    memset(cnt, 0, sizeof(cnt));
    int d = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '0')
        d++;
      else
        d--;
      cnt[d + O]++;
    }
    int ans = 0;
    if (x == 0) ans++;
    for (int i = 0; i < maxn; i++) {
      if (cnt[i] == 0) continue;
      int p = x - (i - O);
      if (d == 0) {
        if (p == 0) {
          ans = -1;
          break;
        }
      } else if (p % d == 0 && p / d >= 0)
        if (cnt[i]) ans += cnt[i];
    }
    cout << ans << endl;
  }
  return 0;
}
