#P7441. 「EZEC-7」Erinnerung

「EZEC-7」Erinnerung

Problem Description

Little Y and Little Z are both elves living in Arcaea Offline. Little Y has infinitely many fallen leaves, where the value of the ii-th leaf is CiC_i. Little Z has infinitely many snowflakes, where the value of the ii-th snowflake is EiE_i. After careful observation by Little X, he found that CC and EE satisfy special conditions:

$$C_i= \begin{cases} x\times i& (x\times i\le K)\\ -K& \text{otherwise} \end{cases}$$$$E_i= \begin{cases} y\times i& (y\times i\le K)\\ -K& \text{otherwise} \end{cases}$$

Little Y and Little Z can perform some operations on these leaves and snowflakes. Each time, they choose one leaf and one snowflake whose sum of values is K\ge K, and then combine them into a colorful memory (Erinnerung). After that, this snowflake and this leaf disappear, and they cannot be used in later operations.

Little X wants to know the maximum number of operations they can perform.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT, indicating the number of test cases.

The next TT lines each contain three non-negative integers x,y,Kx,y,K.

Output Format

For each test case, output one integer, representing the maximum number of operations. Output the answers for each test case on separate lines.

2
2 3 10
2 4 11
3
2
1
0 0 1
0

Hint

Sample Explanation

For the first test case of Sample 1, the values of the leaves are 2,4,6,8,10,10,102,4,6,8,10,-10,-10\dots, and the values of the snowflakes are 3,6,9,10,103,6,9,-10,-10\dots. In the first operation, choose the 44-th leaf and the 11-st snowflake, with sum 1111. In the second operation, choose the 22-nd leaf and the 22-nd snowflake, with sum 1010. In the third operation, choose the 55-th leaf and the 33-rd snowflake, with sum 1919. Thus, they can perform 33 operations. It is easy to prove that there is no better solution.

For the second test case, two possible operations are: choosing the 44-th leaf and the 11-st snowflake, and choosing the 22-nd leaf and the 22-nd snowflake.

For Sample 2, all leaves and snowflakes have value 00, so it is impossible to find a leaf and a snowflake with sum 1\ge 1.


Constraints

  • Subtask 1 (30 points): x,y,K,T10x,y,K,T\le 10.
  • Subtask 2 (70 points): No special constraints.

For 100%100\% of the testdata, 0x,y10100\le x,y\le 10^{10}, 1K10101\le K\le 10^{10}, 1T1051\le T\le 10^5.

Translated by ChatGPT 5