($H,$N)=glob<>; $x=1; $x+=$_>$H for<>; print$x,(0,st,nd,rd)[$x%10]||th