One measure of "unsortedness" in a sequence is the number of pairs of entries that are out of order with respect to each other. For example, in the sequence "DAABEC", this measure is , since D is greater than four letters to its right and E is greater than one letter to its right. This measure is called the number of inversions in the sequence. The sequence "AACEDGG" has only one inversion (E and D) — it is nearly sorted, while the sequence "ZWQM" has inversions (it is as unsorted as can be — exactly the reverse of sorted).
You are required to sort given DNA sequences (each consisting only of the four letters A, C, G, and T). However, you must sort them, not in alphabetical order, but based on "sortedness", from "most sorted" to "least sorted". All sequences are of the same length.
The first line contains an integer , then a blank line followed by datasets. There is a blank line between datasets.
The first line of each dataset contains two integers: the length of the sequences (0 < n \le 50) and the number of sequences (0 < m \le 100). They are followed by lines, each containing a sequence of length .
For each dataset, output the list of input sequences, arranged from "most sorted" to "least sorted". If two or more sequences are equally sorted, list them in the same order as in the input.
Print a blank line between consecutive datasets.
Example 1