// BAPC06 Decompression, Marijn Kruisselbrink
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int r[1000000];
char s[1000000], u[1000000];
int cmp(const void *aa, const void *bb) {
	int *a = (int*)aa;
	int *b = (int*)bb;
	if (u[*a] == u[*b]) return *a-*b;
	return u[*a] - u[*b];
}
void solve() {
	char *c = s, *j, *o = u;
	int N, i=0, cur;
	for (scanf("%s", c); *c; j = c-1) {
		if (isdigit(*c)) {
			for (cur = *c - '0'; *++c && isdigit(*c);) cur = 10*cur + *c - '0';
			while (--cur) *o++=*j;
		} else *o++ = *c++;
	}
	for (N=o-u; i<N; i++) r[i] = i;
	qsort(r, N, sizeof(*r), cmp);
	for (cur = strchr(u, '.')-u; i--;) putchar(u[cur=r[cur]]);
	putchar('\n');
}
int main() {
	int n; scanf("%d", &n); while (n--) solve();
	return 0;
}
