Chef on a trip
All submissions for this problem are available.
Chef bought a one-way ticket from somewhere to somewhere with some changes of trains.
For example: A->B B->C C->DE DE->F
After he received the tickets, Unfortunately he messed up the tickets and forgot the order of the ticket.
Help chef rearrange the tickets to make the tickets in correct order.
Transfer trains at a city more than once doesn't make any sense. So chef will not do that.
The first line contains the number of test cases T.
For each test case, it starts with an integer N. There are N train tickets follow.
Each of the next 2 lines contains the source and destination of a train ticket.
For each test case, output sorted list of train tickets. Each train segment in the list should be outputted as pair of source-destination railway station code.
1 ≤ T ≤ 100.
1 ≤ N ≤ 100 (for 20 points)
1 ≤ N ≤ 10^4 (for 100 points)
1 4 AB PQR AAA XYZ SFO AAA XYZ AB Output:
SFO-AAA AAA-XYZ XYZ-AB AB-PQR
|Time Limit:||1 - 2 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, FS|
Fetching successful submissions