<>; map{ $x=$_+0?9:0; s/.(?=(.?))/$1.0?($&+$1)%9:''/ge while/../; print$_+0||$x,$/; }<>