#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
using namespace std;
using l = long int;
using ll = long long int;
istream& operator>>(istream& cin, vector<ll>& a) {
  for (auto& i : a) cin >> i;
  return cin;
}
ostream& operator<<(ostream& cout, pair<ll, ll>& a) {
  cout << a.first << " " << a.second << "\t";
  return cout;
}
ostream& operator<<(ostream& cout, vector<l>& a) {
  for (auto& i : a) cout << i << " ";
  return cout;
}
ostream& operator<<(ostream& cout, vector<ll>& a) {
  for (auto& i : a) cout << i << " ";
  return cout;
}
ostream& operator<<(ostream& cout, vector<pair<ll, ll>>& a) {
  for (auto& i : a) cout << i << "\t";
  return cout;
}
ostream& operator<<(ostream& cout, vector<vector<l>>& a) {
  for (auto& i : a) {
    cout << i << endl;
  }
  return cout;
}
ostream& operator<<(ostream& cout, vector<vector<ll>>& a) {
  for (auto& i : a) {
    cout << i << endl;
  }
  return cout;
}
ostream& operator<<(ostream& cout, unordered_map<ll, bool>& a) {
  for (auto& i : a) {
    cout << i.first << " " << i.second << "\t";
  }
  return cout;
}
ostream& operator<<(ostream& cout, map<ll, ll>& a) {
  for (auto& i : a) {
    cout << i.first << " " << i.second << "\t";
  }
  return cout;
}
ostream& operator<<(ostream& cout, set<ll>& a) {
  for (auto i : a) cout << i << " ";
  return cout;
}
const ll inf = 1e9 + 7;
int main() {
  l t = 0;
  cin >> t;
  while (t--) {
    ll n, x;
    cin >> n >> x;
    string s;
    cin >> s;
    ll sum = 0;
    for (auto i : s) {
      if (i == '1')
        sum--;
      else
        sum++;
    }
    if (!sum) {
      bool flag = false;
      ll s1 = 0;
      for (auto i : s) {
        if (i == '1')
          s1--;
        else
          s1++;
        if (s1 == x) {
          flag = true;
          break;
        }
      }
      if (flag) {
        cout << "-1\n";
        continue;
      }
      if (x)
        cout << 0 << endl;
      else
        cout << 1 << endl;
      continue;
    }
    ll s1 = 0, count = 0;
    for (auto i : s) {
      if (i == '1')
        s1--;
      else
        s1++;
      if ((x - s1) % sum == 0 && ((x - s1) / sum) >= 0) count++;
    }
    if (!x) count++;
    cout << count << endl;
  }
  return 0;
}
