You are given a puzzle board where there are n words. Initially they are scattered. Your task is to find a order of the words such that the first character of ith word is same as the last character of the (i-1)th word (1 < i ≤ n).
For example, you are given {"abef", "pqrs", "fzzp", "zama", "pxrp"}, the solution is - {"zama", "abcf", "fzzp", "pxrp", "pqrs"}.
Input
Input starts with an integer T (≤ 20), denoting the number of test cases.
Each case starts with a line containing two an integer n (1 ≤ n ≤ 1000). Each of the next n lines contains a word whose length is between 1 and 20 (inclusive). You can assume that the words contain lowercase letters only.
Output
For each case, print the case number and Yes
if such a ordering can be possible, or No
if there is no such ordering.
If the result is yes, then in the next line you should print the n words in a valid order. Print a single space between two consecutive words. There can be multiple solutions, any valid one will do.
Sample
Sample Input | Sample Output |
---|---|
2 5 abcf pqrs fzzp zama pxrp 3 yes no notsolvable | Case 1: Yes zama abcf fzzp pxrp pqrs Case 2: No |
Notes
This is a special judge problem. Wrong output format maycause wrong answer.