B. Word Generator
time limit per test
5 s
memory limit per test
256 megabytes
input
standard input
output
standard output

A machine has $$$M$$$ slots numbered from $$$1$$$ to $$$M$$$, where cards with letters can be placed. Each slot $$$i$$$ can only be filled with cards from a specific set of available cards for that slot. When all $$$M$$$ slots are filled, the letters in the cards form a word by concatenating the letters from left to right across the slots.

Each card can only be used once to create words.

A word is considered beautiful if and only if all of its characters are distinct. For example, the words abchd, a, and ab are beautiful, while the words abdsa and aa are not.

The task is to determine the maximum number of distinct beautiful words that can be created using the available cards for each slot.

Figure 1. The first test from the sample.

Input

The first line contains one integer $$$T$$$ ($$$1 \leq T \leq 10^3$$$), the number of test cases. Then, for each test case:

  • The first line contains one integer $$$M$$$ ($$$1 \leq M \leq 26$$$).
  • Then, $$$M$$$ lines follow, each containing one string $$$S_i$$$, the set of cards that can be used for slot $$$i$$$. It is guaranteed that for each $$$c \in S_i$$$, we have $$$c \in \{\texttt{a}, \texttt{b}, \ldots, \texttt{z}\}$$$.

The total sum of $$$|S_i|$$$ across all test cases does not exceed $$$10^6$$$.

Output

For each test:

  • First, print one line consisting of one integer $$$C$$$, the maximum number of words that you can create.
  • Then, print $$$C$$$ lines, each consisting of one string $$$W_i$$$, words which you created.
Example
Input
2
4
aaab
abcd
ccd
ade
3
aaabc
abbbc
abccc
Output
3
bcda
adce
abcd
5
abc
abc
abc
cab
bca