ll@t;rep(t){ll@m,x=0;rep(i,1,10){ll@d;rep(d)x=x*10+i;}x*=1d9;wt(x+(-x)%%m);}