Ban in Purgatory

0

0 votes
Easy
Problem

'A real sin... can't be erased, no matter whaaat you do' - Ban

Ban is currently in the purgatory to help and bring back original meliodas back to Liones. However just as he was going to meet meliodas he was confronted by demon king. Demon king told ban that there is only one way to lift curse from meliodas and that is by bringing him all the gold from Nayasa. Nayasa could be thought of as an array consisting of gold('G') and silver('S') coins. Each cell has only one coin either gold or silver.

Demon king has given ban the power of griva to convert silver coins to gold but beware!! this power can turn gold back to silver also. Using Griva One time, Ban can select consecutive segment(subarray) of size P. Since Ban is weak he wants to know what is the minimum number of times he needs to use power of griva on Nayasa as he might also be required to battle demon king after that and so he asked you to help him solve this problem. Though one must know the power to solve this question lies in his own sins. There might be(demon king ain't sure) cases when it is not possible to turn all the coins in niyasa to gold(We want no silver coins). In such case print -1.

"Someday I'll definitely make you mine" - Ban

INPUT FORMAT:
The first line contains 'T' = no. of test cases.
Each Test Case contain 2 lines - 

two integers N and P separated by space, as described in the problem statement.

A line containing only 'G' and 'S'

OUTPUT FORMAT:
For each testcase, print a single integer representing the minimum number of times Ban will use the power of griva(so that he get all gold from niyasa) if possible, else print -1.

CONTRAINTS:
1 <= T <= 102
1 <= N <= 30000
1 <= P <= N

Sample Input
1
3 1
S G S
Sample Output
2
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Use Griva once on 0 index. -> G G S

then on index 2. -> G G G

Editor Image

?