아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Spoonerisms

시간 제한2초메모리 제한512 MB

요약
단어 목록에서 A=pq, B=rs로 나눌 때 C=rq와 D=ps도 목록에 있는 두 단어를 찾는다. 네 부분은 모두 비어 있지 않고 p≠r, s≠q여야 한다.
난이도

보통10점 중 7점

유형
문자열, 해시맵, 구현, 완전 탐색
정답자
아직 제출이 없습니다

문제

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 (A,B)(A,B) of words from the list which can be split into A=pqA = pq and B=rsB = rs in such a manner that the words C=rqC = rq and D=psD = ps are also on the list. We allow only true spoonerisms, that is, those with p≠rp \neq r, s≠qs \neq q and p,q,r,sp, q, r, s nonempty.

입력

The first line of input contains the number of test cases zz. The descriptions of the test cases follow.

The first line of each test case contains the length of the list nn (1≤n≤500,0001 \leq n \leq 500\\,000). Each of the following nn lines contains a single word composed of small English letters. The total length of words in all test cases does not exceed 500,000500\\,000.

출력

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 AA and BB, and another one containing CC and DD. If there are multiple solutions, output any one of them. You may also safely switch the word order in any line.

예제1

  1. 예제 1

    입력
    1
    9
    blunder
    blushing
    crow
    cry
    crushing
    blow
    black
    back
    clap
    
    예상 출력
    YES
    blushing crow
    crushing blow