#include <bits/stdc++.h>
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, x;
    cin >> n >> x;
    string s;
    cin >> s;
    long long int sum = 0;
    map<long long int, long long int> m;
    long long int have = (x == 0);
    for (auto x1 : s) {
      if (x1 == '0')
        sum += 1;
      else
        sum -= 1;
      if (sum == x) have = 1;
      m[sum]++;
    }
    if (sum == 0) {
      if (have == 1)
        cout << -1 << endl;
      else {
        cout << 0 << endl;
      }
      continue;
    }
    long long int ans = (x == 0);
    for (auto x1 : m) {
      long long int n1 = (x - x1.first);
      ;
      if (n1 > 0 && sum < 0 || n1 < 0 && sum > 0) continue;
      n1 = abs(n1);
      long long int d = abs(sum);
      ;
      if (n1 % sum == 0) {
        ans += x1.second;
      }
    }
    cout << ans << endl;
  }
  return 0;
}
