Skill Tree

For each triangular region of a weighted infinite triangle grid, compute the total cost of all cells in the region modulo 1e9+7.

Medium7CombinatoricsMathPrefix sumNumber theoryNo attempts yetTime limit2sMemory limit512 MB

Problem

A game that Hyukjung plays added a sixth job advancement. Its skill tree is an equilateral triangular grid that continues downward without end.

Row xx of the grid holds xx cells, and the yy-th cell from the left in that row is written (x,y)(x, y). The cell below and to the left of (x,y)(x, y) is (x+1,y)(x+1, y), and the cell below and to the right is (x+1,y+1)(x+1, y+1).

Learning the skill at the top vertex (1,1)(1, 1) costs 11 won. If the skill in some cell costs kk won, the cell below and to the left costs AkAk won and the cell below and to the right costs BkBk won.

The skill tree has NN special triangles. The special triangle written as the three numbers xix_i, yiy_i, mim_i takes cell (xi,yi)(x_i, y_i) as its top vertex and covers mim_i rows. That is, for each jj with 0jmi10 \le j \le m_i - 1, the j+1j + 1 cells from (xi+j,yi)(x_i + j, y_i) through (xi+j,yi+j)(x_i + j, y_i + j) belong to that triangle. Every time you learn all the skills inside one special triangle, your total damage doubles.

Help Hyukjung and find the cost of learning every skill inside each special triangle.

Input

The first line holds AA and BB, separated by a space. (1A,B1091 \le A, B \le 10^9)

The second line holds the number of special triangles NN. (1N1000001 \le N \le 100\,000)

Each of the next NN lines holds three integers xix_i, yiy_i, mim_i separated by spaces, describing one special triangle. (1yixi10181 \le y_i \le x_i \le 10^{18}, 1mi10181 \le m_i \le 10^{18})

Output

Print NN lines. On each line print the cost of learning every skill inside the corresponding special triangle, modulo 109+710^9 + 7, in the order the triangles are given.