#!/usr/bin/perl

@lines = <STDIN>;
chomp @lines;

foreach (@lines) {
  my @foo = split '';
  push @all, \@foo;
  print sort @foo;
  print "\n";
}

for $aa (0..8) {
  my @temp = ();
  for $bb (0..8) {
    push @temp, $all[$bb][$aa];
  }  
  print sort @temp;
  print "\n";
}

