#!/usr/bin/perl

use v5.30;
use strict;

my $row = join('', 'a' .. 'p');
# my $row = join('', 'a' .. 'e');

chomp (my $dance = <>);
my @dance = split /,/, $dance;

sub do_dance {
	for my $move (@dance) {
		chomp $move;
		if ($move =~ /s(\d+)/) {
			$row =~ s/(.*)(.{$1})/\2\1/;
		} elsif ($move =~ /x(\d+)\/(\d+)/) {
			my ($a, $b) = (substr($row, $1, 1), substr($row, $2, 1));
			substr($row, $1, 1) = $b;
			substr($row, $2, 1) = $a;
		} elsif ($move =~ /p(\w)\/(\w)/) {
			eval "\$row =~ y/$1$2/$2$1/";
		}
	}
}

my %seen;
my $i = 0;
while (1) {
	if ($seen{$row}) {
		last;
	} else {
		$seen{$row} = $i;
	}
	do_dance();
	$i++;
}

my $period = $i - $seen{$row};
say "period $period from $seen{$row} to $i";

my $count = 1_000_000_000 - $seen{$row};
$count %= $period;
do_dance() while $count--;

say $row;

