/(\pl)(?{++$$1})(.)(?{--${$l{$1}=$2}})^/for<>; exit!print-1if(($_)=@c=grep$$_>1,A..Z)>1; print,$_=$l{$_}while$_