Bob is the owner of a shop named "Color Maker". He has 256 types of watercolor in his shop. The types are numbered from 0 to 255. Bob stores the watercolors in small boxes. One box contains only one type of watercolor and there can be more than one box containing the same type of watercolor. Bob keeps the boxes on a shelf side by side. As he has a limited supply of watercolors, he sells the boxes of watercolors with a condition applied.
Bob arranges another set of sample boxes containing watercolors and keeps them on another shelf side by side. He does not sell these sample boxes.
After that, Bob numbers the boxes. Let the number of boxes on the first shelf is and the number of the sample boxes is . Then Bob numbers the boxes on the first shelf from 1 to and the sample boxes from 1 to .
When Alice wants to buy watercolors in this shop, Bob asks her to choose a box. If she chooses the -th box, Bob finds out a position in the sample boxes and the number of boxes such that:
, , , ..., , where represents the -th box on the first shelf, represents the -th box of the sample boxes and , , and . Bob then sells boxes to Alice.
Surprisingly, Bob notices that there can be multiple ways and multiple values of possible. Alice demands that among the ways, he has to choose the way in which the value of is maximized and has to sell boxes. Since calculating the maximum possible value of p is tough for Alice, she asks you to calculate this on behalf of her.
The first line of the input contains two integers (), () - the number of boxes on the first shelf and the number of the sample boxes.
The second line contains space-separated integers. the -th integer represents the type of the watercolor -th box contains.
The third line contains space-separated integers. the -th integer represents the type of the watercolor -th sample box contains.
The next line contains an integer (), the number of the queries. In each of the next lines, there will be an integer (), the position of the box Alice chooses.
Other Constraints:
For each query, print in this format in a single line (without quotes): "Query x: y", where is the number of the query and is the maximum possible value of described in the statement.
Input | Output |
---|---|
6 5 14 25 90 14 81 12 14 14 81 12 0 3 5 2 4 | Query 1: 2 Query 2: 0 Query 3: 3 |
In the third Query, Alice chooses the box. So, . To maximize the value of , the best way is to select the position 2 in the sample boxes. So, . Thus, , , . Here, , , and , , . As 3 boxes are matched in this way, the value of is 3 here and its the maximum among other ways. represents the boxes on the first shelf, represents the sample boxes. |