AtCoder Grand Contest 045
F
Division into Multiples
AtCoder
⌀ 4383
原题
← E→
翻译中…

Problem Statement

翻译中…

Snuke has $X+Y$ balls. $X$ of them have an integer $A$ written on them, and the other $Y$ of them have an integer $B$ written on them.

翻译中…

Snuke will divide these balls into some number of groups. Here, every ball should be contained in exactly one group, and every group should contain one or more balls.

翻译中…

A group is said to be good when the sum of the integers written on the balls in that group is a multiple of an integer $C$. Find the maximum possible number of good groups.

翻译中…

Solve $T$ test cases for each input file.

翻译中…

Constraints

翻译中…
  • $1 \leq T \leq 2 \times 10^4$
  • $1 \leq A,X,B,Y,C \leq 10^9$
  • $A \neq B$
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format. The first line is as follows:

翻译中…

T

翻译中…

Then, $T$ test cases follow. Each test case is given in the following format:

翻译中…

A X B Y C

翻译中…

Output

翻译中…

For each test case, print a line containing the maximum possible number of good groups.

翻译中…

样例

Input #1
3
3 3 4 4 5
2 1 1 5 3
3 1 4 2 5
Output #1
2
2
0
In the first test case, we can have two good groups by making the following groups: $\{3,3,4\}$ and $\{3,4,4,4\}$. In the second test case, we can have two good groups by making the following groups: $\{2,1\}, \{1,1,1\},$ and $\{1\}$.
题目信息
题号
agc045_f
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。