Problem1472--Common permutation

1472: Common permutation

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2  Solved: 2
[Submit] [Status] [Web Board] [Creator:]

Description

Given two strings A and B, output the longest string X that can be created as a substring of A or a substring of B by reversing the order of the letters.

Input

The number of test cases T is entered. (1 <= T <= 20)
For each test case, two strings are entered on two lines, one per line.
All characters are entered in lowercase letters, and the length of the strings is 1,000 or less.

Output

For each input test case, print X line by line.
If there are multiple X's that satisfy the above conditions, print the one that comes first in alphabetical order.

Sample Input Copy

3
pretty
women
walking
down
the
street

Sample Output Copy

e
nw
et

Source/Category