Under construction

Still being built. Things may change

Alley

Interview

Time limit1sMemory limit1024 MB

Summary
Given floats in street order, decide whether a single dead-end alley used as a stack can sort them by license plate.
Level

Medium5 of 10

Topics
Stack, Greedy, String
Solved
No attempts yet

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, NN (1≤N≤1001 \le N \le 100). Each of the following NN lines contains one test case.

Each test case begins with the number of floats, FF (1≤F≤1001 \le F \le 100), followed by FF 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).

Examples1

  1. Example 1

    Input
    6
    4 AAD AAA AAC AAB
    5 1 2 3 4 5
    5 5 4 1 2 3
    5 5 4 2 1 3
    5 4 5 1 2 3
    5 5 4 2 3 1
    
    Expected output
    Yes
    Yes
    Yes
    Yes
    No
    No