Prime Divisor on Tree Path

Limits 1s, 512 MB

You are given a permutation of PPP numbers which are 111 to PPP and a tree with NNN nodes each node having a number written on it. Then you will be given QQQ queries. In each query you will be given 4 numbers: p1p_1p1​ p2p_2p2​ v1v_1v1​ v2v_2v2​. You have to multiply all the numbers written on the nodes which are on the path from node v1v_1v1​ and v2v_2v2​, let the multiplication is mmm. Then you have to perform some steps. In each step, you have to:

This is a companion discussion topic for the original entry at