#! /usr/bin/perl -w
#

sub search {
    my ($sofar, $n, $sref) = @_;

    my $placed = scalar(@$sofar);

    $sref->{$placed}->{join('-', @$sofar)} = 1;
    return if $placed == $n;

    for(my $nxt = 0; $nxt < $n; $nxt++){
	my $ind;

	for($ind = 0; $ind < $placed; $ind++){
	    last if $sofar->[$ind] == $nxt ||
		$ind + $sofar->[$ind] == $placed + $nxt ||
		$ind - $sofar->[$ind] == $placed - $nxt;
	}
	next if $ind != $placed;

	push @$sofar, $nxt;
	search($sofar, $n, $sref);
	pop @$sofar;
    }

    return;
}
    
 
MAIN: {
    my $mx = shift || 8;


    for(my $n=1; $n <= $mx; $n++){
	my $states = {};

	search([], $n, $states);

	printf "%02d: ", $n;

	for(my $placed = 1; $placed <= $n; $placed++){
	    printf " %02d",
	    scalar(keys %{ $states->{$placed} });
	}
	
	print "\n";
    }
}