Result

AC

Duration

3278ms

Code [DL]

s=""+require("fs").readFileSync(0)
i=s.search(/T/)
s=s.replace(RegExp(`\n(.{${i}}).`,"g"),"\n$1#")
s=s.replace(/K *#/,m=>`K${"#".repeat(m.length-1)}`)
console.log(s)

stdin

                           T                      
                                                  
                                                  
                                                  
                                                  
                                                  
                                                  
          K                                       

stdout

                           T                      
                           #                      
                           #                      
                           #                      
                           #                      
                           #                      
                           #                      
          K#################                      

stderr

strace