($R,$K)=glob<>;
($H,$W)=glob<>;
@_=map[/./g],<>;
if($R==0){
	for$y(0..$H-1){
		for(1..$K){
			for$x(0..$W-1){
				print$_[$y][$x]x$K
			}
			print$/
		}
	}
}elsif($R==90){
	for$x(0..$H-1){
		for(1..$K){
			for$y(0..$W-1){
				print$_[$y][$x]x$K
			}
			print$/
		}
	}
}elsif($R==180){
	for$y(reverse 0..$H-1){
		for(1..$K){
			for$x(reverse 0..$W-1){
				print$_[$y][$x]x$K
			}
			print$/
		}
	}
}else{
	for$x(reverse 0..$H-1){
		for(1..$K){
			for$y(reverse 0..$W-1){
				print$_[$y][$x]x$K
			}
			print$/
		}
	}
}