#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(0);
int t;
cin >> t;
while (t--) {
int n, k, num = 0;
string s;
vector<int> ans;
cin >> n >> k >> s;
reverse(s.begin(), s.end());
for(int i = 0; i < s.size() - 1; i++){
if(s[i] == '1')num ++;
else num --;
if(num > 0)ans.push_back(num);
}
sort(ans.rbegin(), ans.rend());
for(int i = 0; i < ans.size(); i++){
k -= ans[i];
if(k <= 0){
cout << i + 2 << endl;
break;
}
}
if(k > 0)cout << "-1\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAgICBjaW4udGllKDApLT5zeW5jX3dpdGhfc3RkaW8oMCk7CiAgICBpbnQgdDsKICAgIGNpbiA+PiB0OwogICAgd2hpbGUgKHQtLSkgewogICAgICAgIGludCBuLCBrLCBudW0gPSAwOwogICAgICAgIHN0cmluZyBzOwogICAgICAgIHZlY3RvcjxpbnQ+IGFuczsKICAgICAgICBjaW4gPj4gbiA+PiBrID4+IHM7CiAgICAgICAgcmV2ZXJzZShzLmJlZ2luKCksIHMuZW5kKCkpOwogICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBzLnNpemUoKSAtIDE7IGkrKyl7CiAgICAgICAgICAgIGlmKHNbaV0gPT0gJzEnKW51bSArKzsKICAgICAgICAgICAgZWxzZSBudW0gLS07CiAgICAgICAgICAgIGlmKG51bSA+IDApYW5zLnB1c2hfYmFjayhudW0pOwogICAgICAgIH0KICAgICAgICBzb3J0KGFucy5yYmVnaW4oKSwgYW5zLnJlbmQoKSk7CiAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IGFucy5zaXplKCk7IGkrKyl7CiAgICAgICAgICAgIGsgLT0gYW5zW2ldOwogICAgICAgICAgICBpZihrIDw9IDApewogICAgICAgICAgICAgICAgY291dCA8PCBpICsgMiA8PCBlbmRsOwogICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYoayA+IDApY291dCA8PCAiLTFcbiI7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==