#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC optimization("O3")
using namespace std;
const unsigned long long mod = 1000000007;
const long long inf = ((1ll << 31ll) - 1ll);
const long long INF = (((1ll << 59ll) - 1ll) * 2ll) + 1ll;
const long double pi = acos(-1);
const long long MAXN = 100000;
vector<bool> Criba(MAXN + 1);
void iniciar_criba() {
  for (long long i = 2; i <= MAXN; i += 2) Criba[i] = 2;
  for (long long i = 3; i <= MAXN; i += 2) {
    if (!Criba[i]) {
      Criba[i] = i;
      for (long long j = i * i; j <= MAXN; j += (2 * i))
        if (!Criba[j]) Criba[j] = i;
    }
  }
}
bool isprime(long long tupac) { return (Criba[tupac] == tupac); }
long long GCD(long long q, long long r) {
  if (r == 0) return q;
  return GCD(r, q % r);
}
long long LCM(long long q, long long r) { return q * (r / GCD(q, r)); }
long long qpow(long long b, long long e) {
  if (!e) return 1;
  if (e & 1) return qpow(b, e - 1) * b % mod;
  long long pwur = qpow(b, e >> 1);
  return pwur * pwur % mod;
}
long long InverM(long long a, long long b) {
  long long eso = a - (a / b) * b;
  if (eso == 0) return 0;
  long long ans = (1 - b * InverM(b, eso)) / eso;
  if (ans < 0) ans += b;
  return ans;
}
long long t, n, D, m, k, bL, bR;
void problem() {
  long long x;
  vector<long long> Flag;
  cin >> n >> x;
  for (long long i = 0; i <= 2 * n; i++) {
    Flag.push_back(0);
  }
  string s;
  cin >> s;
  long long au = 0;
  long long L = 0;
  long long R = 0;
  for (long long i = 0; i < n; i++) {
    Flag[au + n]++;
    if (s[i] == '1')
      au--;
    else
      au++;
    L = min(L, au);
    R = max(R, au);
  }
  if (au == 0) {
    if (x >= L && x <= R) {
      cout << -1;
      return;
    } else {
      cout << 0;
      return;
    }
  }
  if (au > 0) {
    if (x < L) {
      cout << 0;
    } else {
      long long cont = 0;
      if (x > R) {
        long long a = (x - R - 1) / au;
        x -= (a + 1) * au;
      }
      while (x >= L) {
        cont += Flag[x + n];
        x -= au;
      }
      cout << cont;
      return;
    }
  } else {
    if (x > R) {
      cout << 0;
    } else {
      long long cont = 0;
      if (x < L) {
        long long a = (L - x - 1) / (-au);
        x += (a + 1) * (-au);
      }
      while (x <= R) {
        cont += Flag[x + n];
        x -= au;
      }
      cout << cont;
      return;
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(0);
  srand(time(NULL));
  cin >> t;
  while (t--) {
    problem();
    cout << '\n';
  }
  return 0;
}
