Noah is a traveller who wants to travel to different places. He knows in a unique pattern between various cities. But here’s a catch, he wants to travel in a unique pattern between various cities. Since he’s having a hard time choosing the path he wants to travel, he has decided that starting from the first city (s1) he’ll move to the next city which is closest to it (s2) and then he’ll move to the next city closest to it and so on.
Given the number of paths and the closest cities, print the order in
which Noah has to travel. Assume that the city which comes first (last
line of Input) is closest to him.
The first line is an integer which denotes the number of paths P
• The next P lines take two space separated strings s1 and s2
• The last line after P lines takes a single string as input which
denotes the city the traveller visits first
• 1 <= P <= 100
1<= length of each string <= 100
• The output consists of a single string in each line which denotes
the path the traveller has to travel
Note: s1 to s2 denotes a path from City A to City B but NOT from city B to city A
EXECUTION TIME LIMIT