import java.io.*; import java.util.*; class Node { private Node lnode, rnode; private int value; private Node() { lnode = rnode = null; value = -1; } private static Node parseRoot(StringReader sr) throws IOException { if(sr.read() != '(') { throw new IllegalStateException(); } Node node = parseNode(sr); return node; } private static Node parseNode(StringReader sr) throws IOException { Node node = new Node(); int c; c = sr.read(); if(c == ')') { return node; } if(c == '(') { node.lnode = parseNode(sr); c = sr.read(); } if(c != ',') { throw new IllegalStateException(); } c = sr.read(); if(c == '(') { node.rnode = parseNode(sr); c = sr.read(); } if(c != ')') { throw new IllegalStateException(); } return node; } private int order(int n) { if(lnode != null) n = lnode.order(n); value = ++n; if(rnode != null) n = rnode.order(n); return n; } public static Node create(String s) throws IOException { StringReader sr = new StringReader(s); Node node = parseRoot(sr); node.order(0); return node; } public String toString() { String s = Integer.toString(value); if(lnode != null) s += " " + lnode.toString(); if(rnode != null) s += " " + rnode.toString(); return s; } } public class trees { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while(true) { String s = br.readLine(); if(s.equals("()")) break; System.out.println(Node.create(s)); } } }