#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int T = 1, n, m;
  string str;
  cin >> T;
  while (T--) {
    long long int p = 0, q = 0, tmp = 0, sum = 0, count = 0;
    int flag = 0;
    long long int x;
    cin >> n >> x;
    cin >> str;
    if (x == 0) sum++;
    long long int bal[n];
    int n0 = 0, n1 = 0;
    for (int i = 0; i < n; ++i) {
      if (str[i] == '0') {
        n0++;
      } else
        n1++;
      bal[i] = n0 - n1;
    }
    long long int bs = bal[n - 1];
    if (bs == 0) {
      for (int i = 0; i < n; ++i) {
        if (bal[i] == x) {
          flag = 1;
          break;
        }
      }
      if (flag) {
        cout << -1 << "\n";
      } else
        cout << 0 << "\n";
    } else if (bs > 0) {
      for (int i = 0; i < n; ++i) {
        if (bal[i] <= x && (x - bal[i]) % bs == 0) flag++;
      }
      cout << flag + sum << "\n";
    } else {
      for (int i = 0; i < n; ++i) {
        if (bal[i] >= x && (x - bal[i]) % bs == 0) flag++;
      }
      cout << flag + sum << "\n";
    }
  }
  return 0;
}
