Bessie and Jonell are great friends. Since Farmer John scrambles where the cows graze every day, they are sometimes quite far from each other and can't talk.
The pastures and paths on FJ's farm form a 'tree' structure. Each pasture has exactly one distinct path to any other pasture, and each pasture (except pasture #1, the 'root') also has a single parent node.
Bessie and Jonell have decided that they will always meet at the closest pasture that that is both an ancestor of Jonell's pasture and of Bessie's pasture.
FJ created a map of his N (1 <= N <= 1,000) pastures (conveniently numbered 1..N) that tells the parent

(1 <=

<= N) of each pasture except pasture 1, which has no parent.
FJ has released his daily grazing schedule for the next M (1 <= M <= 1,000) days, so Bessie and Jonell are deciding where they should meet each day for gossip. On day k, Bessie is in pasture

(1 <=

<= N) and Jonell is in pasture

(1 <=

<= N).
Given a map and schedule, help Bessie and Jonell find their meeting places.