beecrowd | 2958

The Bad Vibes Walk

By Samuel Eduardo da Silva, IFSULDEMINAS/UFF BR Brazil

Timelimit: 1

College is a memorable time in life. Great things happen, but also a lot of pain and suffering, and in those moments good friends are needed. Knowing this, when he entered the university, Uhrisson soon made good friends and founded his help group, Rolê Bad Vibes, which helped members with problems of course and life. Since they are a group of very intelligent people, they worked out a scheme to solve the problems: For each problem, a value of 1 to 9 (on the criticality scale) was given, and a letter, D or V, indicating a discipline or life problem, respectively. With this data, put in an array, printed on a large cardboard glued to the group headquarters for easy viewing of all. The matrix is ​​a good way of visualizing, but it still causes confusion when choosing the problems to be solved in the day, because the data is very sparse. Thus, Úrisson would like to generate an ordered report of these data. The criterion adopted is: independent of criticality, life problems must be solved first, since they have found it very difficult to reconcile these problems with the problems of disciplines. Then just order by criticity. Urisson, asked you, a programming veteran, to create a program that generates this report.

Input

The first line of the entry contains two integers N and M, indicating, respectively, the number of rows and columns. In the next lines, the matrix is ​​given where each cell contains two characters, the first indicating the level of criticality and the second if it is a life or discipline problem.

Output

Report ordered as requested by Úrisson.

Input Sample Output Sample

3 3
7V 1D 2D
2D 1V 1V
3V 5V 9D

7V
5V
3V
1V
1V
9D
2D
2D
1D