#include <bits/stdc++.h>
using namespace std;
int t;
int n, x;
char s[100005];
int B;
int main() {
  ios::sync_with_stdio(false);
  cin >> t;
  while (t--) {
    cin >> n >> x;
    cin >> s + 1;
    B = 0;
    int cnt = 0;
    for (int i = 1; i <= n; ++i) {
      if (s[i] == '0')
        ++B;
      else
        --B;
    }
    bool flag = 0;
    if (B == 0) {
      if (x == 0) {
        cout << -1 << endl;
        continue;
      }
      for (int i = 1; i <= n; ++i) {
        if (s[i] == '0')
          ++cnt;
        else
          --cnt;
        if (cnt == x) {
          cout << -1 << endl;
          flag = 1;
          break;
        }
      }
      if (flag)
        continue;
      else
        cout << 0 << endl;
    } else {
      int ans = 0;
      for (int i = 1; i <= n; ++i) {
        if (s[i] == '0')
          ++cnt;
        else
          --cnt;
        if (abs(x - cnt) % abs(B) == 0 && (x - cnt) / B >= 0) ++ans;
      }
      cout << ans + (x == 0 ? 1 : 0) << endl;
    }
  }
  return 0;
}
