m@main=getLine>>=print.f.map read.words>>m f[0,_]=0 f[x,y]=x`mod`y+10*f[x`div`y,y]