Académique Documents
Professionnel Documents
Culture Documents
The government wants to build a new hospital. The hospital will have several wings where doctors will do
medical procedures. Some medical procedures require the previous execution of other ones and the use of
some specific surgery tools. In order to offer the best service, and to optimize resources, it has been defined
that the hospital design must fulfill the following rules:
h3 Two medical procedures P and Q must be done at the same wing when both procedures require a
common surgery tool or when the execution of one of them (P or Q) is required to proceed with the
execution of the other one.
You have been hired to build a program to determine the number of wings required in the hospital,
respecting the given rules. For each required wing the program must show the medical procedures that it will
offer and the surgery tools that must be located in the wing.
INPUT
An input file with data for several test cases. The first input line contains an integer number N which indicates
the number of test cases. Following this line there are N test case descriptions to solve.
Within a test case, a medical procedure is identified by a unique uppercase letter (using english alphabet)
and a tool by a unique integer number.
• A line with a number M (1<M≤26) indicating the number of medical procedures in the case.
• M lines, each one with the identifier of a medical procedure Z followed by the identifiers of the medical
procedures that are required for the execution of procedure Z and then by the identifiers of the specific
surgery tools used in procedure Z. Items are separated by blanks.
OUTPUT
Answers for the proposed test cases, in the same order that they were presented.
• For each needed wing, a line that contains the identifiers of the medical procedures carried out in the
wing, in alphabetical ascending order and separated by one blank, followed by the identifiers of the
surgery tools that are located in the wing, in ascending order.
A - Hospital 1/2
SAMPLE INPUT
2
5
A C 1
B E
C 4
D 2 5
E D 3
3
A B 1
B
C B 3
A - Hospital 2/2