#include
int main()
{
int T,i,top;
char str[1005],ch[1005];
scanf("%d",&T);
while(T--)
{
scanf("%s",str);
top=-1;
for(i=0;str[i]!='\0';i++)
{
if(str[i]>='0'&&str[i]<='9')
{
while((str[i]=='.')||(str[i]>='0'&&str[i]<='9'))
{
printf("%c",str[i]);
i++;
}
printf(" ");
}
if(str[i]=='=')
break;
if(str[i]==')')
{
while(top>=0&&(ch[top]!='('))
{
printf("%c ",ch[top]);
top--;
}
top--;
}
else if(str[i]=='(')
{
top++;
ch[top]=str[i];
}
else if(str[i]=='*'||str[i]=='/')
{
while((ch[top]=='*')||(ch[top]=='/'))
{
printf("%c ",ch[top]);
top--;
}
top++;
ch[top]=str[i];
}
else
{
while(top>=0&&(ch[top]!='('))
{
printf("%c ",ch[top]);
top--;
}
top++;
ch[top]=str[i];
}
}
while(top>=0)
{
printf("%c ",ch[top]);
top--;
}
printf("=\n");
}
return 0;
}