ll@T;rep(T){ll@M,@d[9],a=0;rep(i,9)REP(j,d[i])a=10a+i+1;a*=10**9;if(M<1d9)a+=M-a%M;wt(a);}