import sys from functools import lru_cache Q=[1,8] MAX=81181819 SET=set() while Q: x=Q.pop() if x<=81181819 and x not in SET: SET.add(x) for i in [0,1,8]: y=x*10+i Q.append(y) LIST=sorted(SET,reverse=True) @lru_cache(maxsize=None) def calc(x): if x==0: return 0,[] ANS=1<<60 FROM=[] for s in LIST: if s<=x: k,L=calc(x-s) if k>=8: continue if k>=ANS-1: continue if ANS>k+1: ANS=k+1 FROM=L+[s] return ANS,FROM #for x in range(1000): # print(x,calc(x)) T=int(input()) for tests in range(T): x=int(input()) a=MAX-x Q=[(a,[])] USE={a} flag0=0 while flag0==0: #print(Q) NQ=[] while Q: if len(NQ)>=10: break x,L=Q.pop() for s in LIST: if s>x: continue if s==x: flag0=1 ANS=L+[s] break if x-s not in USE: NQ.append((x-s,L+[s])) if flag0==1: break Q=NQ if flag0==1: break #print(ANS) print(len(ANS)) for ans in ANS: print(ans)