by@k_hanazuki
AC
936ms
say $!=get;say m/K/??.subst('K','R'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 T T T T T T T T T T T T T T T T T T T T T T T T T T T T RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR