map{/ /&&print-($x=s/.\s/++$$m x$&/ger*1e9||1)%$m+$x,$/;$m=$_}<>