시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB52292665.000%

문제

The Avengers are looking for ways to encrypt their messages, to hide information from their many opponents. Iron Man suggests the following approach.

Given several string transformation rules, transform a target string. Each string transformation rule (production) transforms a single letter into two letters, and is applied to the first occurrence of the letter in the target string. If the letter does not appear then the string is unchanged. Once a new string is produced, it is used as the target string of the next transformation rule, until no rules are left.

For instance, the production A → OA applied to the string ”CAT” would yield the string ”COAT”. Applied to the string ”DATA” it would yield the string ”DOATA”.

입력

The first line in the test data file contains the number of test cases (< 100). Each test case consists of two lines. The first line contains a number of transformation rules as pairs of words lhsrhs where lhs is a single letter, and rhs is two letters. The second line contains the list of words to be transformed. You may assume all words are in capital letters.

출력

For each test case, you are to output the transformed words in their original order, separated by spaces on a single line.

출력 형식

정확한 출력 형식은 제출에서 언어를 Java로 설정하면 확인할 수 있다.

예제 입력 1

3
A OO
A BAT ART DATA
A AR A AO A TH
A VS HULK
X HX X UX X LK
X JOINS AVENGERS

예제 출력 1

Transformed strings: OO BOOT OORT DOOTA 
Transformed strings: THOR VS HULK 
Transformed strings: HULK JOINS AVENGERS