Shichikuji new resident deity South Black Snail Temple her job followsthere n new city locate Prefecture X city number 1 n City locate x_i km North shrine y_i km East shrine it possible x_i y_i x_j y_j ne jShichikuji provide electricity city building power station city make connection city electricity so City electricity power station connect City electricity direct connection chain connection build power station City cost c_i yen make connection City City j cost k_i k_j yen km wire connection however wire cardinal direction North South East West Wires cross each wire endpoint city if City City j connect wire wire short path City City j thus length wire City City j connect x_i x_j y_i y_j km Shichikuji want job spend little money possible accord is not world money however die fifth grade smart and new resident deity ask helpand provide Shichikuji follow information minimum yen need provide electricity city city power station build connection madeif multiple way choose city connection obtain construction minimum price print