#!/usr/bin/perl -w

use v5.16;

my %dots;
$; = ',';
while (<>) {
	chomp;
	last if !length;
	$dots{$_}++;
}

my %max;
while (<>) {
	chomp;
	my ($axis, $val) = /fold along (.)=(\d+)/;
	$max{$axis} = $val;

	for (keys %dots) {
		my ($x, $y) = split /,/;
		if ($axis eq 'x' && $x > $val) {
			$dots{2*$val - $x,$y}++;
			delete $dots{$x,$y};
		} elsif ($axis eq 'y' && $y > $val) {
			$dots{$x,2*$val - $y}++;
			delete $dots{$x,$y};
		}
	}
}

for my $y (0 .. $max{y}) {
	for my $x (0 .. $max{x}) {
		print $dots{$x,$y} ? '#' : ' ';
	}
	print "\n";
}

