New Year is coming in Tree Island! In this island, as the name implies, there are
n cities connected by
n-1 roads, and for any two distinct cities there always exists exactly one path between them. For every person in Tree Island, it takes exactly one minute to pass by exactly one road.
There is a weird New Year tradition for runnners in Tree Island, which is called "extreme run". This tradition can be done as follows.
A runner chooses two distinct cities
a and
b. For simplicity, let's denote the shortest path from city
a to city
b as
p1,p2,...,pl (here,
p1=a and
pl=b holds). Then following happens:
-
The runner starts at city a.
-
The runner runs from city a to b, following the shortest path from city a to city b.
-
When the runner arrives at city b, he turns his direction immediately (it takes no time), and runs towards city a, following the shortest path from city b to city a.
-
When the runner arrives at city a, he turns his direction immediately (it takes no time), and runs towards city b, following the shortest path from city a to city b.
-
Repeat step 3 and step 4 forever.
In short, the course of the runner can be denoted as:
Two runners JH and JY decided to run "extremely" in order to celebrate the New Year. JH has chosen two cities
u and
v, and JY has chosen two cities
x and
y. They decided to start running at the same moment, and run until they meet at the same city for the first time. Meeting on a road doesn't matter for them. Before running, they want to know the amount of time they will run.
It is too hard for JH and JY to calculate this, so they ask you for help.
Output
For each test case, print an integer describing the amount of time they should run in minutes. If they have to run for an infinitely long time (in other words, if they never meet at the same city), print -1 instead. If they meet at the beginning of their run, print 0.