railway network city consist n station connect n1 road these station road form tree Station 1 city center for road know time train spend pass road you assume train do not spend time stop Lets define distv time train spend station v station 1this railway network splitte zone name k capital latin letter the zone ith station z_i city center zone a for station guarantee station road station city center zone zone lexicographically small any road completely own zone distant end city centertourist arrive airport soon city center Heres trip station v station 1 happend at moment 0 tourist enter train follow directly station v station 1 the trip distv minute tourist buy ticket subset zone moment ticket zone cost pass_i euro every t minute start trip moment t 2 t ldot control system scan tourist if moment scan tourist zone zone ticket pay fine_i euro Formally zone tourist determine follow way if tourist station 1 city center should not pay fine if tourist station u neq 1 zone z_u if tourist move station x station y directly connect road zone z_x note tourist pay fine multiple time zone Tourist select way buy ticket pay fine minimize total cost trip let fv cost station vUnfortunately tourist do not know current value pass_i fine_i different zone forget location airport he ask query 3 type 1 c cost ticket zone change now pass_i c 2 c cost fine zone change now fine_i c 3 u solve follow problem current value pass fine you give station u consider station v satisfy follow condition z_v z_u the station u path station v station 1 Find value minfv station v follow assumption tourist ticket zone station z_u