//传送门:http: //acm.hdu.edu.cn/showproblem.php?pid=1274
#include <queue>
#include <functional>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <assert.h>
using namespace std;
#define N 15
string s;
int dfs(int p,int len) // P表示当前位置 ,len表示字符串长度
{ // 返回的值为一个括号内的 字符串长度-2
int num = 0; // 当前数字的值
for(int i=p;i<len;i++){ // 从当前位置遍历到 len-1 ,遇到 ')' 跳出
if(s[i]>='a'&&s[i]<='z'){ // 如果当前字符为 字母
int tmp =max(num,1); // num 至少为1
for(int j=0;j<tmp;j++) printf("%c",s[i]); //输出 num遍
num = 0; // 要重置为 0
}else if(s[i]>='0'&&s[i]<='9'){ // 如果当前字符为 数字
num = num * 10 + s[i]-'0';
}else if(s[i]=='('){
int tmp = max(num,1); // 递归下探 tmp 遍
for(int j=0;j<tmp-1;j++) dfs(i+1,len);
i=i+dfs(i+1,len)+1; // 跳过 ("s") 的长度
num=0;
}else return i-p; // 果当前字符为 ')' 跳出
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--){
cin>>s;
dfs(0,s.length());
puts("");
}
return 0;
}