Mary bought a bundle of one way tickets that take her through several transfers. For example, SFO to DFW, DFW to JFK, JFK to MIA, MIA to ORD.
Transferring at the same city twice or more makes no sense, so Mary never buys such an itinerary.
After she received the tickets she shuffled them and forgot the original order. Write a program that sorts the shuffled tickets back into the real itinerary order.