#include<stdio.h>
char string[405],stack1[405],stack2[405];
int main()
{
int n,j,i,t1=-1,t2=-1;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%s",&string);
for(j=0;string[j]!='\0';j++)
{
if((string[j]=='(')||(string[j]=='+')||(string[j]=='-')||(string[j]=='*')||(string[j]=='/')|| (string[j]=='^'))
stack1[++t1]=string[j];
else if(string[j]==')')
while(1)
{
if(stack1[t1]=='(')
{
stack1[t1--]=NULL;
break;
}
stack2[++t2]=stack1[t1];
stack1[t1--]=NULL;
}
else
stack2[++t2]=string[j];
}
printf("%s",stack2);
printf("\n");
for(j=0;stack2[j]!='\0';j++)
stack2[j]=NULL;
for(j=0;stack1[j]!='\0';j++)
stack1[j]=NULL;
t1=-1;t2=-1;j=0;
}
}
I2luY2x1ZGU8c3RkaW8uaD4KY2hhciBzdHJpbmdbNDA1XSxzdGFjazFbNDA1XSxzdGFjazJbNDA1XTsKaW50IG1haW4oKQp7CiAgaW50IG4saixpLHQxPS0xLHQyPS0xOwogIHNjYW5mKCIlZCIsJm4pOwogIGZvcihpPTA7aTxuO2krKykKICB7CiAgICAgc2NhbmYoIiVzIiwmc3RyaW5nKTsKICAgICBmb3Ioaj0wO3N0cmluZ1tqXSE9J1wwJztqKyspCiAgICAgewogICAgICAgIGlmKChzdHJpbmdbal09PScoJyl8fChzdHJpbmdbal09PScrJyl8fChzdHJpbmdbal09PSctJyl8fChzdHJpbmdbal09PScqJyl8fChzdHJpbmdbal09PScvJyl8fCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKHN0cmluZ1tqXT09J14nKSkKICAgICAgICAgICBzdGFjazFbKyt0MV09c3RyaW5nW2pdOwogICAgICAgIGVsc2UgaWYoc3RyaW5nW2pdPT0nKScpCiAgICAgICAgICAgd2hpbGUoMSkKICAgICAgICAgICB7CiAgICAgICAgICAgICAgaWYoc3RhY2sxW3QxXT09JygnKQogICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICBzdGFjazFbdDEtLV09TlVMTDsKICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgc3RhY2syWysrdDJdPXN0YWNrMVt0MV07CiAgICAgICAgICAgICAgc3RhY2sxW3QxLS1dPU5VTEw7CiAgICAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICAgICBzdGFjazJbKyt0Ml09c3RyaW5nW2pdOwogICAgIH0KICAgICBwcmludGYoIiVzIixzdGFjazIpOwogICAgIHByaW50ZigiXG4iKTsKICAgICBmb3Ioaj0wO3N0YWNrMltqXSE9J1wwJztqKyspCiAgICAgc3RhY2syW2pdPU5VTEw7CiAgICAgZm9yKGo9MDtzdGFjazFbal0hPSdcMCc7aisrKQogICAgIHN0YWNrMVtqXT1OVUxMOwogICAgIHQxPS0xO3QyPS0xO2o9MDsKICB9Cn0=