#include <bits/stdc++.h>
using namespace std;
using datatype = long;
int main() {
  std::ios::sync_with_stdio(false);
  int N;
  cin >> N;
  unordered_map<datatype, datatype> mp;
  for (int i = 0; i < N; ++i) {
    datatype sz, target;
    cin >> sz >> target;
    string nums;
    std::getline(cin, nums);
    mp.clear();
    datatype delta{0};
    for (size_t i = 0; i < sz; ++i) {
      char ch;
      cin >> ch;
      if (ch == '0')
        delta++;
      else
        delta--;
      mp[delta]++;
    }
    datatype count{0};
    if (target == 0)
      if (delta == 0)
        count = -1;
      else {
        count = 1;
        for (const auto& el : mp) {
          auto rw = target - el.first;
          if (rw / delta >= 0 && rw % delta == 0) count += el.second;
        }
      }
    else if (delta == 0) {
      if (mp[target] != 0)
        count = -1;
      else
        count = 0;
    } else {
      for (const auto& el : mp) {
        auto rw = target - el.first;
        if (rw / delta >= 0 && rw % delta == 0) count += el.second;
      }
    }
    cout << count << endl;
  }
  return 0;
}
