import java.io.IOException;
import java.util.EmptyStackException;
import java.util.Scanner;
import java.util.Stack;
class ReversePolishNotation {
public static void main(String[] args) throws IOException {
Scanner KB=new Scanner(System.in);
int t=KB.nextInt();
while(t-->0)
{
String s=KB.next();
Stack st=new Stack();
char ch;
for(int i=0;i<s.length();i++)
{
ch=s.charAt(i);
if(ch>='a' && ch<='z')
{
System.out.print(ch);
}
else if(ch==')')
{
try{
System.out.print(st.pop());
}
catch(EmptyStackException e)
{
}
}
else if(ch=='(')
{
}
else
{
st.push(ch);
}
}
}
}
}