Matt has a company, Always Cook Mushroom (ACM), which produces high-quality mushrooms.
ACM has a large field to grow their mushrooms. The field can be considered as a 1000 * 1000 grid where mushrooms are grown in grid points numbered from (1, 1) to (1000, 1000). Because of humidity and sunshine, the productions in different grid points are not the same. Further, the production in the grid points (x, y) is (x + A)(y + B) where A, B are two constant.
Matt,the owner of ACM has some queries where he wants to know the sum of the productions in a given scope(include the mushroom growing on the boundary). In each query, the scope Matt asks is a right angled triangle whose apexes are (0, 0), (p, 0), (p, q) 1<=p, q<=1000.
As the employee of ACM, can you answer Matt’s queries?
Input
The first line contains one integer T, indicating the number of test cases.
For each test case, the first line contains two integers:A, B(0<=A, B<=1000).
The second line contains one integer M(1<=M<=10^5), denoting the number of queries.
In the following M lines, the i-th line contains three integers a, b, x (1<=a, b<=10^6, 1<=x<=1000), denoting one apex of the given right angled triangle is (x, 0) and the slope of its base is (a, b). It is guaranteed that the gird points in the given right angled triangle are all in valid area, numbered from (1, 1) to (1000, 1000).
Output
For each test case, output M + 1 lines.
The first line contains "Case #x:", where x is the case number (starting from 1)
In the following M lines, the i-th line contains one integer, denoting the answer of the i-th query.