#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, x;
    cin >> n >> x;
    string s;
    cin >> s;
    int bal[n];
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      if (s[i] == '0')
        cnt++;
      else
        cnt--;
      bal[i] = cnt;
    }
    if (bal[n - 1] == 0) {
      int flag = 0;
      for (int i = 0; i < n; i++) {
        if (bal[i] == x) {
          flag = 1;
          cout << -1 << endl;
          break;
        }
      }
      if (flag == 0) cout << (x == 0) << endl;
      continue;
    }
    int ans = 0;
    if (x == 0) ans++;
    for (int i = 0; i < n; i++)
      if ((x - bal[i]) % cnt == 0 && (x - bal[i]) / cnt >= 0) ans++;
    cout << ans << endl;
  }
  return 0;
}
