Spoonerisms
시간 제한2초메모리 제한512 MB
단어 목록에서 A=pq, B=rs로 나눌 때 C=rq와 D=ps도 목록에 있는 두 단어를 찾는다. 네 부분은 모두 비어 있지 않고 p≠r, s≠q여야 한다.
문제
A spoonerism (named after William Archibald Spooner, an Oxford pastor who had a habit of inadvertently inventing more of them) is a pair of words that you can change into another pair by swapping their beginnings, for example a "blushing crow" becomes a "crushing blow".
Given a list of words, find a spoonerism among them. Formally: find a pair of words from the list which can be split into and in such a manner that the words and are also on the list. We allow only true spoonerisms, that is, those with , and nonempty.
입력
The first line of input contains the number of test cases . The descriptions of the test cases follow.
The first line of each test case contains the length of the list (). Each of the following lines contains a single word composed of small English letters. The total length of words in all test cases does not exceed .
출력
For each test case, if no spoonerism can be found, output "NO" on a single line. If there is a spoonerism, output a line containing "YES", followed by a line containing words and , and another one containing and . If there are multiple solutions, output any one of them. You may also safely switch the word order in any line.