402795: GYM100883 F Print Mix Strings

Memory Limit:64 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. Print Mix Stringstime limit per test2 secondsmemory limit per test64 megabytesinputstandard inputoutputstandard output

While I was working in the company, the internet broke. I didn't have anything to do without internet, so I decided to write this ACM problem.

We need to mix between two strings and also we should keep the same order for both strings.

Example: if we have s1 = "ab" and s2 = "cd", we can generate six strings:

abcd acbd

acdb cdab

cadb cabd

thank you for your help in ”Count Mix Strings” problem. now I can calculate the complexity and make input and output files. You will be given the two strings and you should print all the distinct strings that could be generated in the alphabetical order.

Input

Your program will be tested on one or more test cases. The first line of the input will be a single integer T, the number of test cases (1 ≤ T ≤ 100).

Followed by the test cases, each test case is on one line. it contains two strings s1 and s2, both strings consist of at least 1 and at most 8 lower case English letters (from a to z).

Output

For each test case, print all the distinct strings that could be generated in the alphabetical order.

print a blank line after each test case.

ExamplesInput
2
a aa
ab cd
Output
aaa

abcd
acbd
acdb
cabd
cadb
cdab

加入题单

上一题 下一题 算法标签: