


The length of each word should be less than or equal to ‘M’.
You can’t break a word, i.e. the entire word should come in the same line and it must not be the case that a part of it comes in the first line and another part on the next line.
The first line of the input contains an integer ‘T’ denoting the number of test cases.
The first line of each Test case should contain two positive integers, ‘N’ and ‘M’, where ‘N’ is the number of words and ‘M’ is the number of characters we require in each line.
Following ‘N’ lines, contains one word each.
Each test case's only line of output should contain an integer denoting the minimum cost required to form the arrangement.
Print the output of each test case in a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= N <= 300
1 <= |words[i]| <= 100
1 <= M <= 100
Time Limit: 1sec
In This Approach, we will calculate the cost of all possible lines using dynamic programming and then calculate the final cost by taking the minimum from every possible line.
The steps are as follows: