시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 128 MB | 0 | 0 | 0 | 0.000% |
A boy named Gil-Dong is playing Computer Strategy game these days. To win this game, he has to find out opponent’s formation and then, he must organize his formation with appropriate soldiers. In this game there are three sorts of soldiers, which are archer, lancer, and horse rider units. An archer unit can beat a lancer unit, and a lancer unit can beat a horse rider unit, and a horse rider unit can beat an archer unit. Your task is to make a program providing Gil-Dong a winning formation of the game with the minimum number of soldiers.
Important Notes:
Your program is to read from standard input. The input consists of T (1≤T≤15) test cases. The number T of test cases is given in the first line of the input. Each test case consists only of one formation of soldiers represented by a string of {A, B, C} in each following line, where ‘A’ denotes a archer unit, ‘B’ denotes a lancer unit, ‘C’ denotes a horse rider unit, respectively. The length of each test case does not exceed 80. You shoud remember that the last soldier of the given formation is involved in the first engagement with the first soldier of Gil-Dong’s formation.
Your program is to write to standard output. Print exactly one line for each test case with a winning formation of the minimum possible length.
3 ABCBCACBA BCCAABCA ACAABBCA
CABCBABAC CBACBA CBACBC