You are visiting a colorful tree in the dream of Electric Sheep, which has at most colors. These colors are numbered from
to
.
The colorful tree has vertices, connected with
edges. Each vertex is painted in some of the colors. Let non-negative integer
denotes the colors of vertex
. If the lowest
-th bit of
is
, the colors that vertex
is painted contains color
. Note that a vertex can be painted in no colors, which means this vertex is transparent.
You also have your own color . When you are travelling on the colorful tree, you can visit vertex
iff the colors of vertex
contains your color
. If you are at vertex
and your color is
, you can do one of the following operations in
second:
Move to vertex that is adjacent to vertex
.
Note that both the colors of vertex and those of vertex
should contain color
.
Choose a color and change your color to
.
Note that the colors of vertex should contain both color
and
.
Now you are planning for trips. The
-th trip is planned from vertex
to another vertex
. You can choose any color you want as your color
at vertex
before the trip. Find out the number of seconds that need to be taken to arrive at vertex
in the optimal way for each trip.
If you can’t reach vertex from vertex
, print
.
The first line contains two positive integers
,
(
,
) — the number of vertices, and the number of trips.
The second line contains
non-negative integers
(
) — the colors of each vertex.
Each line in the following
lines contains two positive integers
,
(
) — the edge connecting vertex
and vertex
.
Each line in the following
lines contains two positive integers
,
(
,
) — the
-th trip from vertex
to vertex
.
For each trip, print the number of seconds that need to be taken in the optimal way in a single line. If vertex
is not reachable from vertex
in the trip, print
.
In the first sample, the optimal way for the
-rd trip from vertex
to vertex
is shown as followings:
Choose color as your own color before the trip at vertex
.
Move to vertex from vertex
. It takes
second.
Move to vertex from vertex
. It takes
second.
Move to vertex from vertex
. It takes
second, and
seconds in total.
The optimal way for the -th trip from vertex
to vertex
is shown as followings:
Choose color as your own color before the trip at vertex
.
Move to vertex from vertex
. It takes
second.
Choose color and change your own color to it. It takes
second.
Move to vertex from vertex
. It takes
second, and
seconds in total.
In the second sample, it is not allowed to visit vertex , so you can’t start the trip at vertex
. It is impossible to travel from vertex
to vertex
, because the colors of vertex
and those of vertex
share no colors.