#include
#include
#include
using namespace std;
void check(string a){
int cnt_index=0,cnt_int=0;
for(unsigned j=0;j
if(a[j]>='0'&&a[j]<='9'){
cnt_int*=10;
cnt_int+=a[j]-'0';
}
else{
if(cnt_int==0){
cnt_int=1;
}
cnt_index=j;
for(int i=0;i<cnt_int;i++){
j=cnt_index;
if(a[j]!='('&&a[j]!=')'){
cout<<a[j];
}
else{
j++;
string c;int nleft=1,nright=0;
while(nleft!=nright){
if(a[j]=='('){
nleft++;
}
if(a[j]==')'){
nright++;
}
if(nleft!=nright){
stringstream stream;
stream << a[j];
c += stream.str();
j++;
}
}
check(c);
}
}
cnt_int=0;
}
}
}
int main(){
int n;
cin>>n;
string *a=new string[n];
for(int i=0;i
cin>>a[i];
}
for(int i=0;i<n;i++){
check(a[i]);
cout<<endl;
}
return 0;
}