#!/usr/bin/perl -w

#$oldline = "";
$oldread = "";
@oldlines = ();

$_=<STDIN>; # read in the header
print;

while($_=<STDIN>) {
  m/^([^\t]+)\t/;
  $read = $1;
  if(($read eq $oldread) || ($oldread eq "")) {
    push(@oldlines, $_);
  } else {
    $len = scalar @oldlines;
    #print STDERR "LENGTHS = $len1;$len2\n";
    @sorted = sort @oldlines;
    undef @oldlines;
    $oldlines = ();
    print $sorted[0];
    for($i=1;$i<$len;$i++) {
      if($sorted[$i] ne $sorted[$i-1]) {
        print $sorted[$i];
      }
    }
    push(@oldlines, $_);
  }
  $oldread = $read;
}

    $len = scalar @oldlines;
    #print STDERR "LENGTHS = $len1;$len2\n";
    @sorted = sort @oldlines;
    undef @oldlines;
    $oldlines = ();
    print $sorted[0];
    for($i=1;$i<$len;$i++) {
      print $sorted[$i];
    }
    
