There are

shops in the city where rain_w lives. And there are

roads connecting these shops, any two shops can reach each other directly or indirectly through these

roads. The length of the

-th road is

, connecting shops

and

.
As we all know, rain_w likes to wear skirts. There are

types of skirts, and each shop only sells one kind of skirt. More formally, the

-th shop only sells the

-th skirt.It is guaranteed that every type of skirt has at least one shop selling it.
Every skirt has its rarity, the

-th skirt is more rare than

-th skirt if and only if there are fewer shops selling skirt

than

. If the number of shops selling them is the same, then the skirt with the smaller id is more rare.
Every day, Rain_w will choose two types of skirts
)
which he wants to buy, (it is guaranteed that

is more rare than

). Then his mother would send him to a shop which sells

-th skirts as a starting point. After buying skirts in this starting point and putting them on, Rain_w will choose another shop that sells one of these of skirts (means sells

or

) and walk to it along the shortest path, and then he will go home in his mother's car. Because Rain_w enjoys the feeling of wearing a skirt, he will choose the shop with the longest distance that he needs to walk.
Rain_w' s mother knows rain_w' s thoughts, but she doesn't want the cute rain_w to walk outside for too long in a skirt. Therefore, she will carefully chooses the starting point to minimize the distance rain_w walks.
There are

days. Each day, you will know the two skirts rain_w choose, you need to write a program to help rain_w calculate how long he will walk with skirt that day with his mother's control.