Sort a scrambled itinerary (Small)

Rebuild each shuffled set of flight tickets into the single chain where each arrival matches the next departure.

Easy3Hash mapGraphInterviewNo attempts yetTime limit5sMemory limit512 MB

Problem

Mary bought a bundle of one way flight tickets that take her through several cities with transfers. For example SFO->DFW, DFW->JFK, JFK->MIA, MIA->ORD, where the arrival airport of each segment is the departure airport of the next one.

Transferring through the same city twice makes no sense, so Mary never buys such an itinerary.

After she received the tickets she shuffled them and forgot the original order. Sort the shuffled tickets back into the real travel order.

Input

The first line contains the number of test cases TT. Then TT test cases follow.

The first line of each test case contains the number of tickets NN. The next 2N2N lines contain the NN tickets in shuffled order. One ticket takes two lines: the first line is the departure airport code and the second line is the arrival airport code. An airport code is three uppercase letters.

Output

For each test case print one line in the form "Case #x: itinerary", where xx is the test case number starting from 1 and itinerary is the list of segments in real travel order.

Write each segment as the departure code and the arrival code joined by a hyphen, for example "SFO-DFW", and separate consecutive segments with a single space.

Constraints

  • 1T1001 \le T \le 100
  • 1N1001 \le N \le 100
  • The tickets of each test case are one itinerary Mary bought, shuffled, so they always rebuild into one valid itinerary.
  • Within a test case the itinerary never visits the same city twice, so the answer is unique.