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

* Let l be a letter of the English alphabet, either lowercase or uppercase (n the sequel, we say simply "a letter"). Then, the object that consists only of l, designating l as its label, is a BUT. In this case, it is called a 0-ary BUT.
* Let l be a letter and C a BUT. Then, the object that consists of l and C, designating l as its label and C as its component, is a BUT. In this case, it is called a unary BUT.
* Let l be a letter, L and R BUTs. Then, the object that consists of l, L and R, designating l as its label, L as its left component, and R as its right component, is a BUT. In this case, it is called a binary BUT.



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

* When a BUT B is 0-ary, its representation is the letter of its label.
* When a BUT B is unary, its representation is the letter of its label followed by the parenthesized representation of its component.
* When a BUT B is binary, its representation is the letter of its label, a left parenthesis, the representation of its left component, a comma, the representation of its right component, and a right parenthesis, arranged in this order.



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 BUT B inductively along the structure of B as follows:


* When B is 0-ary, D consists only of a letter of its label. The letter is called the root of D, and also called the leaf of D
* When B is unary, D consists of a letter l of its label, a minus symbol S, and the diagram C for its component, satisfying the following constraints:
* l is just below S
* The root of C is just above S
l is called the root of D, and the leaves of C are called the leaves of D.
* When B is binary, D consists of a letter l of its label, a sequence of minus symbols S, the diagram L for its left component, and the diagram R for its right component, satisfying the following constraints:
* S is contiguous, and is in a line.
* l is just below the central minus symbol of S, where, if the center of S locates on a minus symbol s, s is the central, and if the center of S locates between adjacent minus symbols, the left one of them is the central.
* The root of L is just above the left most minus symbols of S, and the rot of R is just above the rightmost minus symbol of S
* In any line of D, L and R do not touch or overlap each other.
* No minus symbols are just above the leaves of L and R.
l is called the root of D, and the leaves of L and R are called the leaves of D



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 letter, 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 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.

Examples

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))
.


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


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))
.


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

Solution (in CPP):

Solution:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<b?(a=b,1):0)
#define chmin(a,b) (a>b?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
typedef long long ll;
typedef pair<int,int> pii;

struct BUT {
  int n;                        // n-ary
  char label;
  int c1,c2;                    // component
  BUT() {}
  BUT(char label) : n(0),label(label) {}
  BUT(char label, int c) : n(1), label(label), c1(c) {}
  BUT(char label, int c1, int c2) : n(2), label(label), c1(c1), c2(c2) {}
} buts[1000];

int butnum;

int parse(const string &s) {    // テ」ツδ妥」ツδシテ」ツつケテ」ツ?療」ツ?ヲIDテ」ツつ津ィツソツ氾」ツ??
  if (s.size() == 1) {          // 0-ary
    buts[butnum] = BUT(s[0]);
  } else {
    int comma = -1;
    int cnt = 0;
    REP(i,s.size()) {
      if (s[i] == '(') cnt++;
      else if (s[i] == ')') cnt--;
      if (cnt == 1 && s[i] == ',') comma = i;
    }
    if (comma == -1) {          // unary
      int c = parse(s.substr(2,s.size()-3));
      buts[butnum] = BUT(s[0],c);
    } else {                    // binary
      int c1 = parse(s.substr(2,comma-2));
      int c2 = parse(s.substr(comma+1, s.size()-comma-2));
      buts[butnum] = BUT(s[0],c1,c2);
    }
  }
  return butnum++;
}

typedef pair<vector<string>, int> P;
P diagram(int id) {
  BUT b = buts[id];
  if (b.n == 0) {
    return P(vector<string>(1,string(1,b.label)), 0);
  } else if (b.n == 1) {
    P p = diagram(b.c1);
    vector<string> d = p.first;
    int pos = p.second;
    d.push_back(string(d[0].size(), ' '));
    d.push_back(string(d[0].size(), ' '));
    d[d.size()-2][pos] = '-';
    d[d.size()-1][pos] = b.label;
    return P(d,pos);
  } else {
    P p1 = diagram(b.c1);
    P p2 = diagram(b.c2);
    vector<string> d1 = p1.first, d2 = p2.first;
    int pos1 = p1.second, pos2 = p2.second;
    int h1 = d1.size(), h2 = d2.size();
    int w1 = d1[0].size(), w2 = d2[0].size();
    int h = max(h1,h2);
    int maxdis = w1-pos1 + pos2;

    for (int x12=-w2+1; x12<=w1+1; ++x12) {
      int x1,x2;
      if (x12<0) {
        x1 = -x12;
        x2 = 0;
      } else {
        x1 = 0;
        x2 = x12;
      }
      int w = max(x1+w1,x2+w2);
      int y1 = h-h1, y2 = h-h2;

      // テ・ツキツヲテ」ツ?ョrootテ」ツ?古・ツ渉ウテ」ツ?ョrootテ」ツつ暗」ツつ甘・ツ渉ウテ」ツ?ォテ」ツ??」ツ?淌」ツつ嘉」ツ??」ツつ?
      if (x1+pos1 >= x2+pos2) continue;
      bool ok = 1;
      vector<string> nxt(h+2,string(w,' '));
      bool f[h][w];
      memset(f,0,sizeof(f));
      REP(i,h1) REP(j,w1)
        nxt[i+y1][j+x1] = d1[i][j];
      REP(i,h2) REP(j,w2) {
        if (d2[i][j] != ' ') {
          if (nxt[i+y2][j+x2] != ' ') ok = 0;
          nxt[i+y2][j+x2] =  d2[i][j];
          f[i+y2][j+x2] = 1;
        }
      }
      // cout << h << " " << w << endl;
      // REP(i,h) {
      //   REP(j,w) cout << nxt[i][j];
      //   cout << endl;
      // }
      if (ok) {
        static const int dy[4] = {-1,0,1,0};
        static const int dx[4] = {0,1,0,-1};
        REP(i,h)REP(j,w) {
          if (nxt[i][j] != ' ') {
            REP(k,4) {
              int y=i+dy[k];
              int x=j+dx[k];
              if (valid(y,x,h,w)) {
                if (nxt[y][x] != ' ' && f[i][j] ^ f[y][x]) ok = 0;
              }
            }
          }
        }
        if (ok) {
          int xp1 = x1 + pos1;
          int xp2 = x2 + pos2;
          int npos = xp1 + (xp2-xp1)/2;
          for (int x=xp1; x<=xp2; ++x) nxt[h][x] = '-';
          nxt[h+1][npos] = b.label;
          return P(nxt,npos);
        }
      }
    }
  }
  assert(0);
}

int main() {
  char c;
  int cs = 0;
  do {
    string s;
    while(cin >> c, c!=';'&&c!='.') {
      s += string(1,c);
    }
    // cout << s << endl;
    butnum = 0;
    int root = parse(s);
    vector<string> ans = diagram(root).first;
    printf("%d:\n", ++cs);
    REP(i,ans.size()) {
      int len = ans[i].size();
      for(int j=len-1; j>=0; --j) {
        if (ans[i][j]!=' ') break;
        len=j;
      }
      REP(j,len) cout << ans[i][j];
      cout << endl;
    }
  } while(c != '.');
}