To convince Tianjiang not to remove the Abyss errors, Hefeng would like to better the world using the Abyss errors. She secretly left a blueprint of Chronosphere to her childhood friend Miming, and sent messages about the Abyss AI and the portal to her other friends like Guodong before she went to the Blue Planet with Yunyan again.
After that, since it's the last chance for Yunyan, he's too anxious to care much about Hefeng. So Hefeng toke on her own trip. Hefeng hoped to explore the possibilities of the Abyss power. So when Guodong arrived, they cooperated and made a great success in making games such as ONU and the Land of the Kernel. The game is so popular that even Yunyan had experienced it (of course with the purpose of finding better ways to use magic and fight with Tianjiang).
As expected, Miming successfully created another Chronosphere and used it. Both Hefeng and Yunyan kept their memory. First Hefeng escaped so that Yunyan couldn't take her to the portal. Then Yunyan failed to arrived the portal before Miming's team opened it. Knowing that Guodong would came later and knew how potential he was from the past memory, he decided to wait until Guodong's arrival and make use of Guodong. At the same time, Hefeng was trying to speed up the Abyss Cycle, since when it happens, the Abyss' power, including Yunyan's power, would be temporarily weaken. After Yunyan met Guodong and they went into the portal, Hefeng left a note in the Abyss and followed them into the portal later.
Passing through the portal again needs to use the magic flow skillfully.
The Blue Planet's magic flow has key point indexed from to , the key point need kinds of different magic elements to fix, and specially, every two adjacent key points should not have any same kind of magic elements. That is to say, for every , let denotes the set of magic elements given to the key point, obviously the length of is . And for , .
There're some pieces of sub-flow needs to fix, for every key point from to , you need to use total kinds of magic elements to allocate all the , such that no adjacent key points in the sub-flow have any same element. You need to find the minimal to satisfy the requirement.
However, the magic flow is dynamic, so that changes with time. And there are operations in total, for every operation, either the changes forever, or you should calculate the with given .
输入
The first line contains two integers .
The second line contains integer, the i-th integer is .
Then follow lines, each line has integers
输出
For every query, output one line with one integer denotes the minimal .
样例
标准输入 复制文本 |
3 4 2 3 2 2 3 3 1 3 3 2 1 2 2 1 3 |
标准输出 复制文本 |
2 5 6 |
提示
For the first query in flow piece , , one possible scheme is to allocate , and .
For the second query in flow piece , one possible scheme is to allocate and .
For the third query in flow piece , one possible scheme is to allocate and .