a="#" while a:A=a;a=[];exec"q=raw_input();a+=[''.join(min(b,y*len(b))for y in q)for b in A];"*input() print"\n".join(A)