Nahida is playing a game with her fungi friends, the Aranara, on the branches of the Divine Tree in Sumeru City. On the Divine Tree, there are $$$N$$$ ($$$1 \le N \le 10^5$$$) branches. Initially, Nahida starts at branch $$$a$$$ and the Aranara starts at branch $$$b$$$. In a single turn, Nahida will move from branch $$$a$$$ to $$$nxt_a$$$, and the Aranara will move from branch $$$b$$$ to $$$nxt_b$$$. The game ends when they move to the same position, allowing Nahida to finally catch the Aranara. Unlike in the first version, $$$nxt_i \neq i$$$ is not guaranteed.
Note that Nahida and the Aranara move at the exact same time, so if in one turn Nahida is going from branch $$$1$$$ to $$$2$$$, and the Aranara is going from branch $$$2$$$ to $$$1$$$, then Nahida will not catch the Aranara.
Nahida enjoys playing games, but as the Dendro Archon, she has many duties she must attend to. Thus, she wants to know, for a given starting position $$$(a, b)$$$, if the game will go on forever or not.
Line $$$1$$$: Two integers $$$N$$$ ($$$2 \le N \le 10^5$$$) and $$$Q$$$ ($$$1 \le Q \le 10^5$$$).
Line $$$2$$$: $$$N$$$ space separated integers representing the values of $$$nxt$$$, with the $$$i + 1$$$th line representing $$$nxt_i$$$ ($$$1 \le nxt_i \le N$$$).
Lines $$$3 \dots Q + 3$$$: $$$Q$$$ lines, each containing two integers $$$a_i$$$ and $$$b_i$$$, denoting the starting positions of the $$$i$$$th query.
Line $$$1 \dots Q$$$: The $$$i$$$th line will be either "YES" or "NO" (not case sensitive), denoting if Nahida will ever catch the Aranara in the $$$i$$$th query.
4 2 2 1 2 2 4 3 1 2
YES NO
| Name |
|---|


