BUT We Need a Diagram 

Consider a data structure called BUT (Binary and/or Unary Tree). A BUT is defined inductively as follows:

A BUT can be represented by an expression in the following way.

Here are examples:

a
A(b)
a(a,B)
a(B(c(D),E),f(g(H,i)))

Such an expression is concise, but a diagram is much more appealing to our eyes. We prefer a diagram:

D  H i
-  ---
c E g
--- -
 B  f
 ----
  a

to the expression a(B(c(D),E),f(g(H,i))).


Your mission is to write a program that converts the expression representing a BUT into its diagram. We want to keep a diagram as compact as possible assuming that we display it on a conventional character terminal with a fixed pitch font such as Courier. Let's define the diagram D for a BUT B inductively along the structure of B as follows:

Input 

The input to the program is a sequence of expressions representing BUTs. Each expression except the last one is terminated by a semicolon. The last expression is terminated by a period. White spaces (tabs and blanks) should be ignored. An expression may extend over multiple lines. The number of letters, i.e., the number of characters except parentheses, commas, and white spaces, in an expression is at most 80.


You may assume that the input is syntactically correct and need not take care of error cases.

Output 

Each expression is to be identified with a number starting with 1 in the order of occurrence in the input. Output should be produced in the order of the input.


For each expression, a line consisting of the identification number of the expression followed by a colon should be produced first, and then, the diagram for the BUT represented by the expression should be produced.


For a diagram, output should consist of the minimum number of lines, which contain only letters or minus symbols together with minimum number of blanks required to obey the rules shown above.

Sample Input 

a(A,b(B,C));
x( y( y( z(z), v( s, t ) ) ), u ) ;

a( b( c,
      d(
         e(f),
         g
       )
    ),
   h( i(
         j(
            k(k,k),
            l(l)
          ),
         m(m)
       )
    )
 );

a(B(C),d(e(f(g(h(i(j,k),l),m),n),o),p))
.

Sample Output 

1:
 B C
 ---
A b
---
 a
2:
z s t
- ---
z  v
----
 y
 -
 y u
 ---
  x
3:
   k k l
   --- -
 f  k  l m
 -  ---- -
 e g j   m
 --- -----
c d    i
---    -
 b     h
 -------
    a
4:
j k
---
 i l
 ---
  h m
  ---
   g n
   ---
    f o
    ---
   C e p
   - ---
   B  d
   ----
    a



Miguel A. Revilla
1999-03-05