Split a string into k different non-empty consecutive parts, or report that no such split exists, choosing the lexicographically smallest sequence.
Medium5StringGreedyBacktrackingNo attempts yetTime limit2sMemory limit256 MBHank Morebooks is a famous writer. He has already settled the plot of his new book, but he has not chosen names for k of its characters.
He names characters the same way he did in his earlier books. He builds one string of lowercase English letters, then divides it into k pairwise different non-empty parts. Each part becomes the name of one character.
Decide whether the given string can be divided into k different names.
The input contains several test cases. The first line contains the number of test cases t (1≤t≤1000).
Each test case takes two lines. The first line contains the string to divide. Its length is at most 100 and it contains only lowercase English letters. The second line contains the number of parts k the string must be divided into (1≤k≤5).
For each test case, print the answer as described below.
If the string can be divided into k pairwise different non-empty parts, print YES on the first line, then print the parts, one per line, on the next k lines. Concatenating the parts in the printed order must give the input string.
When several divisions work, print only the one whose parts, read in order, form the lexicographically smallest sequence of strings. Every candidate first part is a prefix of the string, so this rule is the same as taking the first part as short as possible, then taking the next part as short as possible in what is left, and continuing that way to the last part.
If no such division exists, print only NO for that test case.