by@k_hanazuki
AC
1061ms
say $!=get;say m|K|??S|K|{'K'x$!.index('T')-$/.from+1}|!!$! for lines
T K
T T T T T T T T T T T T T T T T T KKKKK