#!/usr/bin/perl

use strict;

my $html;
while(my $line = <STDIN>){
    chomp($line);
    if($line =~ m{^http://}){
	$html = $line;
	next;
    }
    my @lines = split("\t",$line);
    my $country = $html;
    $country =~ s{.*/wiki/}{};
    $lines[2] = "(no dst)" if($lines[2] eq '-');
    if($lines[3] =~ m{([^NS]+)_([NS])_([^WE]+)_([WE])_}){
	$lines[3] = $1." ".$2;
	$lines[4] = $3." ".$4;
	$lines[3] =~ tr/A-Z/a-z/;
	$lines[4] =~ tr/A-Z/a-z/;
    }
    unshift(@lines,$country);
    print join("\t",@lines),"\n";
}
