{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003e Matt has a company, Always Cook Mushroom (ACM), which produces high-quality mushrooms. \u003cbr\u003e\u003cbr\u003e 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. \u003cbr\u003e\u003cbr\u003e 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\u0026lt;\u003dp, q\u0026lt;\u003d1000. \u003cbr\u003e\u003cbr\u003e As the employee of ACM, can you answer Matt’s queries? \u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":" The first line contains one integer T, indicating the number of test cases.\u003cbr\u003e\u003cbr\u003e For each test case, the first line contains two integers:A, B(0\u0026lt;\u003dA, B\u0026lt;\u003d1000).\u003cbr\u003e\u003cbr\u003e The second line contains one integer M(1\u0026lt;\u003dM\u0026lt;\u003d10^5), denoting the number of queries.\u003cbr\u003e\u003cbr\u003e In the following M lines, the i-th line contains three integers a, b, x (1\u0026lt;\u003da, b\u0026lt;\u003d10^6, 1\u0026lt;\u003dx\u0026lt;\u003d1000), 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)."}},{"title":"Output","value":{"format":"HTML","content":" For each test case, output M + 1 lines.\u003cbr\u003e\u003cbr\u003e The first line contains \"Case #x:\", where x is the case number (starting from 1) \u003cbr\u003e\u003cbr\u003e In the following M lines, the i-th line contains one integer, denoting the answer of the i-th query."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n0 0\r\n3\r\n3 5 8\r\n2 4 7\r\n1 2 3\r\n1 2\r\n3\r\n3 5 8\r\n2 4 7\r\n1 2 3\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003eCase #1:\r\n1842\r\n1708\r\n86\r\nCase #2:\r\n2901\r\n2688\r\n200\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}