use bigint;

# mask of permutations seen so far x last 2 symbols -> count
my %classes;
$classes{0}{"**"} = 1;

my %configuration2bit = (
	"123" => 1,
    "132" => 2,
    "213" => 4,
    "231" => 8,
    "312" => 16,
    "321" => 32,
);

my $a6 = 0;
foreach my $n (1..100) {
	$a6 *= 3;

	my %newclasses = ();
	foreach my $mask (keys %classes) {
		foreach my $last2symbols (keys %{$classes{$mask}}) {
			foreach my $symbol (1..3) {
				my $newmask = $mask | $configuration2bit{$last2symbols . $symbol};
				my $newlast2symbols = substr($last2symbols,1) . $symbol;

				if ($newmask==63) {
					$a6 += $classes{$mask}{$last2symbols};
				} else {
					$newclasses{$newmask}{$newlast2symbols} += $classes{$mask}{$last2symbols};
				}
			}
		}
	}
	%classes = %newclasses;

	print $n, " ", $a6/6, "\n";
}