Result

AC

Duration

1061ms

Code [DL]

say $!=get;say m|K|??S|K|{'K'x$!.index('T')-$/.from+1}|!!$! for lines

stdin

                  T                               
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
              K                                   

stdout

                  T                               
                  T                               
                  T                               
                  T                               
                  T                               
                  T                               
                  T                               
                  T                               
                  T                               
                  T                               
                  T                               
                  T                               
                  T                               
                  T                               
                  T                               
                  T                               
                  T                               
              KKKKK                                   

stderr

strace