The stable marriage problem consists of matching members of two different sets according to the members' preferences for members of the other set. The input for the problem consists of:
a set of males;
a set of females;
for each male and female, a list of all the members of the opposite gender in order of preference (from the most preferable to the least).
A marriage is a one-to-one mapping between males and females. A marriage is called stable if there is no pair such that f \in F prefers m \in M to her current partner and prefers over his current partner. A stable marriage is called male-optimal if there is no other stable marriage where any male matches with a female he prefers more than the one assigned in .
Given preference lists for males and females, you must find the male-optimal stable marriage.
The first line contains the number of test cases. The first line of each test case contains the integer (0 < n < 27). The next line contains the names of males and females. Male names begin with uppercase letters, female names with lowercase letters. Then follow lines describing the males' preference lists. The next lines describe the females' preference lists.
For each test case, print the pairs of the stable marriage which is male-optimal. The pairs in each test case must be output in lexicographical order of the male names, as shown in the example. Output an empty line between test cases.
Example 1