%$_=%{$_-1},++$$_{+getc}for 1..<>;$\=<>;map{/ (\d+)/;$-=$';$_=a;$_++while$--=$$1{$_}-${$`-1}{$_};print}<>