rendered paste body#include<stdio.h>
#include<math.h>
int main(void)
{
char st[500],ch[500],eq[500],top;
long int x,y,z,m;
int prod(char,char);
top='+';
scanf("%ld",&m);
while(m--&&m<=100)
{
scanf("%s",st);
x=0;
y=0;
z=-1;
while(st[x]!='\0')
{
if(st[x]>64&&st[x]<92||st[x]>96&&st[x]<123)
ch[y++]=st[x];
else if(st[x]==')')
{
while(eq[z]!='(')
ch[y++]=eq[z--];
top=eq[--z];
}
else
{
while(z>=0&&prod(top,st[x])==1)
{
ch[y++]=top;
top=eq[--z];
}
eq[++z]=st[x];
top=st[x];
}
x++;
}
while(z>=0)
{
if(eq[z]=='(')
z--;
else
ch[y++]=eq[z--];
}
ch[y]='\0';
for(x=0;x<y;x++)
printf("%c",ch[x]);
}
return(0);
}
int prod(char g,char r)
{
if(r=='('||r=='$')
return 0;
else if(g=='$'||g=='*'||g=='/')
return 1;
else if(r=='*'||g=='('||r=='/')
return 0;
else
return 1;
}