#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n, x;
    cin >> n >> x;
    cin.ignore();
    string s;
    cin >> s;
    long long* balance = new long long[n];
    if (s[0] == '0') {
      balance[0] = 1;
    } else {
      balance[0] = -1;
    }
    for (int i = 1; i < n; i++) {
      if (s[i] == '0') {
        balance[i] = balance[i - 1] + 1;
      } else {
        balance[i] = balance[i - 1] - 1;
      }
    }
    long long ans;
    if (x == 0) {
      ans = 1;
    } else {
      ans = 0;
    }
    if (balance[n - 1] == 0) {
      if (find(balance, balance + n, x) == balance + n) {
        cout << "0 \n";
      } else {
        cout << "-1 \n";
      }
    } else {
      for (int i = 0; i < n; i++) {
        if ((x - balance[i]) % balance[n - 1] == 0 &&
            (x - balance[i]) / balance[n - 1] >= 0) {
          ans++;
        }
      }
      cout << ans << '\n';
    }
    delete[] balance;
  }
  return 0;
}
