// BAPC06 Decompression, Marijn Kruisselbrink
import java.util.*;
import java.io.*;
       class Main {
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		int n = sc.nextInt();
		while (n-- > 0) new Main().solve();
	}

	void printf(String f, Object... a) {
		System.out.printf(f, a);
	}
	
	void solve() {
		String data = sc.next();
		StringBuilder sb = new StringBuilder();
		for (int i = 0, j = 0; i < data.length(); j = i++) {
			if (Character.isDigit(data.charAt(i))) {
				int cnt = data.charAt(i) - '0';
				while (++i < data.length() && Character.isDigit(data.charAt(i))) {
					cnt = 10 * cnt + data.charAt(i) - '0';
				}
				--i;
				while (--cnt>0) sb.append(data.charAt(j));
			} else {
				sb.append(data.charAt(i));
			}
		}
		String st = sb.toString();
		char[] uo = st.toCharArray();
		int N = uo.length;
		int[] r = new int[N];
		r[0] = st.indexOf('.');
		int p = 1;
		for (char c = 'A'; c <= 'Z'; c++) {
			for (int j = 0; j < uo.length; j++) {
				if (uo[j] == c) {
					r[p++] = j;
				}
			}
		}
		int cur = r[0];
		try {
			// !!!!!! Zonder deze BufferedWriter er tussen is dit programma ongeveer 10x zo langzaam
			// waarschijnlijk zal eerst naar een StringBuilder schrijven ook wel snel genoeg zijn
			BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
			for (int i = 0; i < N; i++) {
				bw.write(uo[cur = r[cur]]);
			}
			bw.write('\n');
			bw.flush();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
