Alley
InterviewTime limit1sMemory limit1024 MB
Given floats in street order, decide whether a single dead-end alley used as a stack can sort them by license plate.
Problem
In the industrial city of ACM, the grand buildings and the most gentrified neighborhoods are said to make it the city of gold. People call it the city where dreams come true.
Your friends have thrown you a party on the most luxurious parade float during the yearly festival Jour Régionaux, to celebrate your promotion to technical director at your firm.
Your limo suddenly stops on the street. Outside, the directors of the floats in the parade are arguing. Their floats have ended up out of order, just before they go out to perform for the waiting crowd.
You offer to help. Nearby there is a side alley. Neither the street nor the alley is wide enough for one float to pass another. No float can go backwards down the main street. The alley is a dead end, but floats can be stored there temporarily. At any time, the float in the alley closest to the street may return to the street and continue along its route.
The parade director gave you a list of the floats in their correct order. The license plates on that list are sorted, but the floats on the street are not.
Can you put the parade back in order?
Input
The first line contains the number of test cases, (). Each of the following lines contains one test case.
Each test case begins with the number of floats, (), followed by distinct license plates giving the floats in their initial order. Each license plate has between one and three characters from the set 0-9 and A-Z.
Output
For each test case, print a single line containing Yes if you can rearrange the floats into sorted order by license plate, or No otherwise. For sorting, 0 < 9 < A < Z, and if one plate is a prefix of another, the shorter one comes first (0 < 00 < 0Z < 1).