import java.util.*;
class fund {
public static void main(String args[])
{
int cases,length,top=0;
char exp[]=new char[399];
char stack[]=new char[200];
Scanner sc=new Scanner(System.in);
cases=sc.nextInt();
while(cases>0)
{
exp=sc.next().toCharArray();
length=exp.length;
for(int i=0;i<=length-1;i++)
{
if(exp[i]== '(' )
continue;
if(exp[i]== ')' )
{
System.out.print(stack[top]);
top--;
}
else if(exp[i]=='+' || exp[i]=='-' || exp[i]=='*' || exp[i]=='/' || exp[i]=='^')
{
top++;
stack[top]=exp[i];
}
else
{
System.out.print(exp[i]);
}
}
}
}
}