We want to make a 3x3 horizontal-and-vertical word puzzle like the one below.

Across clues
Down clues
You are given 6 words. Use 3 of them as the rows and the other 3 as the columns to form a 3x3 puzzle. Each column, read from top to bottom, must also be one of the given words. Every word may be used only as many times as it appears in the input.
The input contains 6 lines. Each line contains one 3-letter word consisting of uppercase English letters. The words are sorted in lexicographic order, and the same word may appear more than once.
If it is impossible to use all 6 words to form a 3x3 puzzle, print 0. Otherwise, print the 3 row words of the puzzle from top to bottom, one per line.
If there is more than one possible puzzle, print the one whose 9-letter string formed by concatenating the three output rows is lexicographically smallest.