There’s a zebra crossing appearing in the middle of nowhere with NN blocks in it. The colors of the zebra crossing is represented by a binary string SS, where SiSi is 1 if the ii-th block from the left is white, and 0 if the block is black.

There’s a zebra crossing appearing in the middle of nowhere with NN blocks in it. The colors of the zebra crossing is represented by a binary string SS, where SiSi is 1 if the ii-th block from the left is white, and 0 if the block is black.

Chef really wants to play with the zebra crossing. Although the given zebra crossing might not have alternate black and white blocks, Chef wants to follow the alternating white-black color pattern while crossing it.

Initially, Chef stands at block 11. Chef has to jump exactly KK times, and in each jump he has to move forward and jump to a different color than that previously occupied by Chef. More formally, suppose that Chef is currently at block ii and wants to jump to block jj then following conditions should hold:

  • i<ji<j
  • SiSjSi≠Sj

Output the farthest block Chef can reach with exactly KK jumps. If Chef cannot jump exactly KK times, output -1.

Input Format

  • The first line contains an integer TT denoting the number of test cases. The TT test cases then follow.
  • The first line of each test case contains two integers NN and KK.
  • The second line of each test case consists of a binary string of length NN denoting the color of blocks of the zebra crossing.

Output Format

For each test case, output the farthest block Chef can reach with exactly KK jumps, or -1 in case Chef cannot jump exactly KK times.

Constraints

  • 1T1051≤T≤105
  • 2N1032≤N≤103
  • 1KN1≤K≤N
  • Sum of NN over all test cases does not exceed 51055⋅105

Sample Input 1 

3
6 2
100101
5 1
10111
6 1
000000

Sample Output 1 

6
2
-1

Explanation

  • For the first test case, Chef can jump in the following order: 1561→5→6.

  • For the second test case, Chef can jump in the following order: 121→2.

  • For the third test case, Chef cannot make any jumps.

Fake GCD solution codechef 

Cars and Bikes solution codechef

Adjacency Hatred solution codechef

Leave a Reply

Your email address will not be published. Required fields are marked *

*