403238: GYM101086 J Smooth Developer

Memory Limit:256 MB Time Limit:8 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

J. Smooth Developertime limit per test8 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Noura has been recently working on developing Android Applications with coach Alaa Jrad. One of her tasks was to develop an application to help coach Alaa with teaching Geometry to his contestants, so she decided to use coach Fegla's geometry library, as it is one of the best in the region. But while using coach Fegla's geometry library, if you need the code of the function IsPointOnSegment, for example, you will also need to include the function collinear in the code. In a similar manner, the function collinear might yet require other functions to run.

Given the dependencies of each function, and the list of the functions Noura will use, help her find the names of all the functions she needs to include from the library to get her code to compile.

Input

The first line of input contains an integer T (1 ≤ T ≤ 128), the number of test cases.

The first line of each test case contains two space - separated integers N (1 ≤ N ≤ 105), the number of functions in the library, and K (1 ≤ K ≤ N) the number of the functions Noura will use. Then N lines follow, each line will be in the following format:

Si Ci Fi, 1 Fi, 2 ... Fi, Ci

Where Si represents the name of the ith function, Ci (0 ≤ Ci ≤ i) represents the number of functions the ith function depends on, then followed by a list of Ci distinct function names, each represents the name of a function the ith function depends on. It's guaranteed that all function names in the list appeared in the input before. A function can depend on itself (recursive function).

The last line of each test case contains K distinct function names, the list of the functions that Noura is going to use.

Function name doesn't exceed 15 letters and contains only lowercase and uppercase English letters.

Output

For each test case, print the functions Noura needs to include, each on a single line, following the same order of appearing in the input file.

ExamplesInput
2
2 1
cross 0
polygonArea 1 cross
polygonArea
6 2
intersect 0
circlePoint 0
intLines 1 intersect
circleThree 1 intersect
circleTwo 0
mec 3 circlePoint circleTwo mec
intersect mec
Output
cross
polygonArea
intersect
circlePoint
circleTwo
mec
Note

Warning: large Input/Output data, be careful with certain languages.

加入题单

算法标签: