#!/usr/bin/perl

@lines = <STDIN>;
chomp @lines;

$giant = join(" ",@lines);

@boardtext = ();

for $board (1..11) {
  $bp = $board + 1;
  $giant =~ /Board $board (.*)Board $bp/;
  push @boardtext, $1;
}

$giant =~ /Board 12 (.*)/;
push @boardtext, $1;

$bnum = 1;
foreach $text (@boardtext) {
  $text =~ /Dlr: (\w+) .*? Vul: (\S+)(.*?)Contract Ld Res Score NS (.*)/;
  $dealer = $1;
  $vul = $2;
  $hands = $3;
  $ntext = $4;
  @pieces = ();
  $ohands = $hands;
  while ($hands =~ s/ ([SHCD] [AKQJT98765432]+) / /) {
    push @pieces, $1;
  }
  splice(@pieces, 0, 0, "S") if ($pieces[0] =~ /^H/);
  splice(@pieces, 1, 0, "H") if ($pieces[1] =~ /^D/);
  splice(@pieces, 2, 0, "D") if ($pieces[2] =~ /^C/);
  splice(@pieces, 3, 0, "C") if ($pieces[3] =~ /^S/);
  splice(@pieces, (($ohands =~ / S S /) ? 4 : 5), 0, "S") if ($pieces[5] =~ /^H/);
  splice(@pieces, (($ohands =~ / H H /) ? 6 : 7), 0, "H") if ($pieces[7] =~ /^D/);
  splice(@pieces, (($ohands =~ / D D /) ? 8 : 9), 0, "D") if ($pieces[9] =~ /^C/);
  splice(@pieces, (($ohands =~ / C C /) ? 10 : 11), 0, "C") if ($pieces[11] =~ /^S/);
  splice(@pieces, 12, 1) if ($pieces[12] !~ /^S/ and $pieces[13] =~ /^S/);
  splice(@pieces, 13, 1) if ($pieces[13] !~ /^H/ and $pieces[14] =~ /^H/);
  splice(@pieces, 14, 1) if ($pieces[14] !~ /^D/ and $pieces[15] =~ /^D/);
  splice(@pieces, 15, 1) if ($pieces[15] !~ /^C/ and $pieces[16] =~ /^C/);
  $ttext = join("\n", @pieces[0..3]) . "\n";
  $ltext = join("\n", $pieces[4], $pieces[6], $pieces[8], $pieces[10]) . "\n";
  $rtext = join("\n", $pieces[5], $pieces[7], $pieces[9], $pieces[11]) . "\n";
  $btext = join("\n", @pieces[12..15]) . "\n";
  @hands = ();
  if ($hands =~ " west east ") {
    @north = (0,1,2,3);
    @west = (4,6,8,10);
    @east = (5,7,9,11);
    @south = (12,13,14,15);
  } elsif ($hands =~ " south north ") {
    @north = (5,7,9,11);
    @west = (0,1,2,3);
    @east = (12,13,14,15);
    @south = (4,6,8,10);
  } elsif ($hands =~ " east west ") {
    @north = (12,13,14,15);
    @west = (5,7,9,11);
    @east = (4,6,8,10);
    @south = (0,1,2,3);
  } elsif ($hands =~ " north south ") {
    @north = (4,6,8,10);
    @west = (12,13,14,15);
    @east = (0,1,2,3);
    @south = (5,7,9,11);
  }
  @scores = ();
  while ($ntext =~ s/ [NSEW] \S+ [NSEW] \S+ [NSEW] \S+ [NSEW] \S+ (\S+ \S+ \S+ \S+ \S+ \S+)//) {
    push @scores, $1;
  }
  print "Board: $bnum Dealer: $dealer Vulnerability: $vul\n";
  print "NORTH     EAST      WEST      SOUTH\n";
  format Something = 
@<<<<<<<< @<<<<<<<< @<<<<<<<< @<<<<<<<<
$north, $east, $west, $south
.
  foreach (0..3) {
    $north = $pieces[$north[$_]];
    $west = $pieces[$west[$_]];
    $east = $pieces[$east[$_]];
    $south = $pieces[$south[$_]];
    $~ = 'Something';
    write;
  }
  $pair = 0;
  foreach (@scores) {
    $pair++;
    $blah = "$pair. $_";
    $blah .= " " x (35 - length $blah);
    print "$blah";
    if ($pair == 1) {
      print "         NORTH";
    } elsif ($pair <= 5) {
      print "         ", $pieces[$north[$pair-2]];
    } elsif ($pair <= 6) {
      print "WEST              EAST";
    } elsif ($pair <= 10) {
      $scum = $pieces[$west[$pair-7]];
      $scum .= " " x (18 - length $scum);
      print $scum, $pieces[$east[$pair-7]];
    } elsif ($pair <= 11) {
      print "         SOUTH";
    } elsif ($pair <= 15) {
      print "         ", $pieces[$south[$pair-12]];
    } 
    print "\n";
  }
  print "\n";
  $bnum++;
}

