After studying for a long time how the embryos of organisms become asymmetric during their development, the famous biologist Dr. Podboq has arrived at a new hypothesis. He is now preparing a poster for an upcoming academic conference. The poster shows a tree that represents how an embryo develops from a single cell through repeated cell divisions. Your job is to write a program that transforms such trees into a normalized form so that the audience can grasp the idea more easily.
A tree that represents a process of cell divisions has the form described below.
(Figure F-1 shows an example of such a tree.)
According to Dr. Podboq's hypothesis, we can tell which cells are more or less asymmetric from the structure of this tree. First, the hypothesis defines the left-right similarity of a cell as follows.
For example, consider the tree below.
(Figure F-2: an example tree.)
The left-right similarity of cell A is computed as follows. Among the descendants of cell B, the left child of A, three distinct structures occur. Note that even though the last of them occurs three times, when counting kinds of structures it is counted only once.
(Figure F-3 shows the structures occurring among the descendants of B.)
Among the descendants of cell C, the right child of A, four distinct structures occur.
(Figure F-4 shows the structures occurring among the descendants of C.)
The first, second, and third structures on the B side are the same as the second, third, and fourth structures on the C side, respectively. Hence there are four distinct structures in total, and three of them are common to both the left and right sides, which means the left-right similarity of A is $3/4$.
Given the left-right similarity of every cell, the hypothesis lets us decide which of two cells X and Y is more asymmetric, using the following rules.
When comparing child cells in the rules above, apply this same set of rules recursively.
Your job is to transform a given cell-division tree, only by swapping the two child cells of chosen cells, into a tree that satisfies the following conditions.
When two child cells are equally asymmetric, their order does not matter, because either order gives a tree of the same shape.
For example, suppose the given tree is the one in Figure F-2. First we compare B and C; because B has the lower left-right similarity, it is more asymmetric, so we keep B on the left and C on the right. Next, because B is a left child of A, we order B's two children so that the more asymmetric one is on the left. Because C is a right child of A, we order C's two children so that the more asymmetric one is on the right. Handling every other cell the same way, the tree is finally transformed into the result shown below.
(Figure F-5 shows the example tree after the transformation.)
Please note that the only operation allowed during the transformation is swapping the two child cells of some parent cell. For instance, you may not transform the tree in Figure F-2 into the one shown in Figure F-6.
The input consists of $n$ lines ($1 \le n \le 100$), each describing one tree, followed by a line that contains only a single $0$, which marks the end of the input. Each tree has at least $1$ and at most $127$ cells. Below is an example of a tree description.
((x (x x)) x)
This description represents the tree shown in Figure F-1. More precisely, a tree description follows one of the two formats below.
"(" <description of the left child tree> <one space> <description of the right child tree> ")"
or
"x"
The former describes a tree whose starting cell has two child cells; the latter describes a tree whose starting cell has no child cell.
For each tree in the input, print one line describing the tree after the transformation. In the output, describe trees using the same format as the input, and print the descriptions in the same order as the input. Each line must contain exactly one tree description and nothing else.