#P7478. [2017年杭电多校]Rikka with Candies
[2017年杭电多校]Rikka with Candies
Rikka with Candies
Problem Description
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them: There are children and kinds of candies. The th child has dollars and the unit price of the th kind of candy is . The amount of each kind is infinity. Each child has his favorite candy, so he will buy this kind of candies as much as possible and will not buy any candies of other kinds. For example, if this child has dollars and the unit price of his favorite candy is dollars, then he will buy two candies and go home with dollars left. Now Yuta has queries, each of them gives a number . For each query, Yuta wants to know the number of the pairs which satisfies if the th child¡¯s favorite candy is the th kind, he will take dollars home. To reduce the difficulty, Rikka just need to calculate the answer modulo . But It is still too difficult for Rikka. Can you help her?
Input
The first line contains a number , the number of the testcases. For each testcase, the first line contains three numbers . The second line contains numbers and the third line contains numbers . Then the fourth line contains numbers , which describes the queries. It is guaranteed that for all .
Output
For each query, print a single line with a single digit -- the answer.
Sample Input
1
5 5 5
1 2 3 4 5
1 2 3 4 5
0 1 2 3 4
Sample Output
0
0
0
0
1
Source
2017 Multi-University Training Contest - Team 5