#!/usr/bin/perl

use strict;
my @data;
while(<STDIN>) {
  chomp;
  my @a = split;
  push @data , \@a;
}
my @sorted = sort { 
  my $n; my $a1 = $a->[1]; my $b1 = $b->[1];  
  if ( $a1 eq "X" || $b1 eq "X" ) { 
    $n = $a1 cmp $b1 } 
  else { $n = $a1 <=> $b1 }; 
  if ( $n == 0 ) { 
    $n = $a->[2] <=> $b->[2] }; 
  return $n} @data;


foreach my $s ( @sorted ) {
  print join ( "\t", @$s ) . "\n";
}

