#include <bits/stdc++.h>
using namespace std;
const int N = 1E5 + 5;
vector<int> vc;
map<int, int> mp;
int cum[N], cum2[N];
int main() {
  int test;
  cin >> test;
  for (int i = 0; i < test; i++) {
    long long int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '0')
        cum[i + 1] = cum[i] + 1;
      else
        cum[i + 1] = cum[i] - 1;
    }
    int z = cum[s.size()];
    int counter = 0;
    for (int i = 0; i < s.size(); i++) {
      if (cum[i + 1] == b && z == 0) {
        counter = -1;
      }
    }
    if (counter != -1) {
      if (b == 0) counter++;
      for (int i = 0; i < s.size(); i++) {
        if (z != 0 && (b - cum[i + 1]) % z == 0 && (b - cum[i + 1]) / z >= 0)
          counter++;
      }
    }
    cout << counter << endl;
  }
  return 0;
}
