m@main=getLine>>=print.foldr1(#).map read.words>>m 0#_=0 n#b=10*div n b#b+mod n b