#include <bits/stdc++.h>
using namespace std;
const int MAXM = 1e5 + 5;
const int MAXN = 1e6 + 5;
const int INF = 1e7 + 9;
const int MOD = 1e9 + 9;
const int MX = 1e9;
const int X[] = {1, -1, 0, 0}, Y[] = {0, 0, 1, -1};
vector<int> v;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    int n, x;
    cin >> n >> x;
    string s;
    cin >> s;
    map<int, int> mp;
    int cnt = 0, ans = 0;
    for (int j = 0; j < s.size(); ++j) {
      if (s[j] == '0')
        ++cnt;
      else
        --cnt;
      mp[j] = cnt;
    }
    int k = mp[s.size() - 1];
    cnt = 0;
    bool ok = false;
    for (int j = 0; j < s.size(); ++j) {
      if (!k) {
        if (x - cnt == 0) ok = true;
      } else {
        if ((x - cnt) % k == 0)
          if ((x - cnt) / k >= 0) ++ans;
      }
      if (s[j] == '0')
        ++cnt;
      else
        --cnt;
    }
    if (ok)
      v.push_back(-1);
    else
      v.push_back(ans);
  }
  for (auto it : v) cout << it << "\n";
}
