Two goblins want to file a joint petition, but kingdom law is unforgiving: they must present it to their closest shared superior. That superior is the lowest goblin who sits above both of them in the hierarchy (or one of them, if one already outranks the other). The king (goblin 00) is above everyone.

As Indra's fairy godmother, you must answer qq kinship queries: given goblins aa and bb, who is their closest shared superior?

Input

The first line contains two integers nn and qq: the number of goblins and the number of queries.

The next n−1n-1 lines each contain two integers aa and bb, meaning that goblin aa is the superior of goblin bb.

Finally, the next qq lines each contain two integers aa and bb, representing one query.

Output

For each query, output a single integer on its own line: the closest shared superior of goblins aa and bb.

Constraints

  • 1≤n≤1051 \le n \le 10^5
  • 1≤q≤1051 \le q \le 10^5
  • 0≤a,b≤n−10 \le a, b \le n-1
  • The superiors form a tree rooted at goblin 00

Example 1

Input 1
5 4
0 1
0 2
1 3
1 4
3 4
3 2
0 3
4 4
Output 1
1
0
0
4
Explanation
  • Goblins 33 and 44 meet at 11.
  • Goblins 33 and 22 meet at the king 00.
  • Goblins 00 and 33 meet at 00 (the king already outranks 33).
  • A goblin's closest shared superior with themselves is themselves.

Comments0


No comments yet

Be the first to comment.

New comment


Log in to join the discussion.