#!/usr/bin/perl -w

use strict;
use v5.30;

my %screen;
my ($w, $h) = (50, 6);
$; = ',';

while (<>) {
	if (/rect (\d+)x(\d+)/) {
		for my $x (0 .. $1-1) {
		for my $y (0 .. $2-1) {
			$screen{$x,$y} = 1;
		} }
	} elsif (/rotate row y=(\d+) by (\d+)/) {
		my %ns = %screen;
		for my $x (0 .. $w-1) {
			my $sx = $x - $2;
			$sx += $w if $sx < 0;
			$ns{$x,$1} = $screen{$sx,$1};
		}
		%screen = %ns;
	} elsif (/rotate column x=(\d+) by (\d+)/) {
		my %ns = %screen;
		for my $y (0 .. $h-1) {
			my $sy = $y - $2;
			$sy += $h if $sy < 0;
			$ns{$1,$y} = $screen{$1,$sy};
		}
		%screen = %ns;
	}
}

for my $y (0 .. $h-1) {
	for my $x (0 .. $w-1) {
		print $screen{$x,$y} ? '#' : ' ';
	}
	print "\n";
}

