sub o{$|=print@_,$/}++$d,o L while<><1||$m{$y=($x+30**($d&=3))%901}&&$m{$y}^$d^6;$m{$x}=$d^4;$x=$y;o F;<>=~/M/||--$d+o(R)+do$0