import java.io.*;
import java.util.*;

public class Pg     {
    
    public static FileReader fr;
    public static BufferedReader br;
    public static char c;
    public static Stack stack = new Stack();
    public static String line = "";
    public static String postFixExp = "";
    public static String openParen = "";
   


    public static void postfix(){
	
	for(int i = 0; i < line.length() ; i++){
	    c = line.charAt(i);
	    switch(c){
	    
	    case '+':
		precedenceMove();
		break;
	    case '-':
		precedenceMove();
		break;
	    case '/':
		precedenceMove();
		break;
	    case '*':
		precedenceMove();
		break;
	    default:
	       
		postFixExp += c;
		
		
	    }//end switch
	}//end for
	while(!stack.isEmpty()){
	    postFixExp += "" + stack.pop();
	}//end while
       

    }


    public static void precedenceMove(){
	
	
	
while(!stack.isEmpty()){
	   if(((precedence(((Character)stack.peek()).charValue())) <= precedence(c))){
	    //char hehe = ((Character)stack.peek()).charValue();
	    postFixExp = postFixExp +((Character)stack.pop()).charValue();
	}// end while
	   else
	       break;
}
	stack.push(new Character(c));
	//System.out.println(c);
    }





    public static  void infixParenthesizer(){
	String tempA = "";
	String tempB = "";

	for(int i=0; i<postFixExp.length();i++){
	    c =postFixExp.charAt(i);
	    tempA = "";
            tempB = "";
            switch(c){
	    case '+':
		tempA += (String)stack.pop();
		tempB += "(" + (String)stack.pop() + c + tempA + ")";
                stack.push(new String(tempB));
		break;
	     case '-':
		tempA += (String)stack.pop();
		tempB += "(" + (String)stack.pop() + c + tempA + ")";
		stack.push(new String(tempB));
		break;
	    case '*':
		tempA += (String)stack.pop();
		tempB += "(" + (String)stack.pop() + c + tempA + ")";
		stack.push(new String(tempB));
		break;
	    case '/':
		tempA =(String)stack.pop();
		tempB = "(" + (String)stack.pop() + c + tempA + ")";
		stack.push(new String(tempB));
		break;
	    default:
		tempA += c;
                stack.push(tempA);
		break;
	    }//end switch
	}//end for

	postFixExp = (String)stack.pop();
    }



    public static int precedence(char c){
	
	//    System.out.println("c r " +c);
	if(c == '+')return 1;
	if(c == '-')return 1;
	if(c == '*')return 0;			  
	if(c == '/')return 0;
	else return -1;
    }



    public static void main( String[] args ){

	try{
             
        fr  = new FileReader("g.in");
	br = new BufferedReader(fr);
	int index = 1;
	int max = 0;
        String temp = "";
	max = Integer.parseInt(br.readLine());
	while(index<= max){
	    temp = "";
            line = br.readLine();
	    //System.out.println(line);
	    postfix();
	    
	    //System.out.println(postFixExp);
	    infixParenthesizer();
	    //System.out.println("ip");
	    System.out.println("Case #" + index + ":");
            System.out.println(postFixExp);
            System.out.println("");
	    index++;
	}

	}catch(NullPointerException h){System.out.println("kdsdbfg");}
	catch(Exception e){e.printStackTrace();}

    }

}
