import java.util.;
import java.lang.;
import java.io.*;
class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
Stack stack = new Stack();
String exp,temp;
char ch;
int i;
String tst = sc.nextLine();
int t = Integer.parseInt(tst);
while(t>0)
{
exp = sc.nextLine();
System.out.println(exp);
for(i=0;i<exp.length();i++)
{
ch = exp.charAt(i);
if(ch!=’)’)
{
temp=String.valueOf(ch);
stack.push(temp);
}
else
{
temp=stack.pop();
temp+=stack.pop();
temp=stack.pop()+temp;
stack.pop();
stack.push(temp);
}
}
System.out.println(stack.pop());
t-=1;
}
}
}