시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB0000.000%

문제

Remark: We were originally planning to give you this in the real contest, but since we have too many awesome problems for you for tomorrow and this one is just way too easy, we decided to move it to the dress rehearsal as a sneak preview.

In this problem we will be exploring the concept of sorting numbers. Most of you have likely written a sorting algorithm before, but just in case, here is a tutorial: You reorder the numbers to put the smaller ones in front and larger ones in the back.

Having dealt with the theory, we come to practice. You will be given some integers. Please output the same integers in sorted order. Where is the trick, you ask? Well, you might have to deal with equality cases. If two numbers are equal, the one that was the first in the input should also be the first on the output. Other than that, there are no tricks, no complications. Just sort the numbers from lowest to highest. Simple!

Oh, one more thing. When we say some integers, we mean they might be somewhat large integers. To make life easier for you, we will express them in a simple “tower of powers” form. Each integer will be in the format

$$a_1^{a_2^{\dots^{a_n^{}}}}\text{,}$$

where $1 \le a_1, a_2, \dots , a_n \le 100$, and $1 \le n \le 100$. Note that evaluation is from top to bottom, thus

$$a_1^{a_2^{a_3}} = a_1^{\left(a_2^{a_3}\right)}\text{.}$$

Are you done yet? No? Better start working!

입력

The first line of each test case contains the number M of integers in this test case, 1 ≤ M ≤ 100. Each of the next M lines describes one of the M integers. The integer is written as described above, using the carat (^) to represent power, with no whitespace. There will be between 1 and 100 numbers in the representation of each integer, and each of these numbers will be an integer between 1 and 100.

출력

For each test case, display the case number followed by the sorted list of integers, one per line, in the original form.

예제 입력 1

4
2^2^2
3^4
15
9^2

예제 출력 1

Case 1:
15
2^2^2
3^4
9^2