Might and Magic

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

Two heroes are fighting, whose names are hero 00 and hero 11 respectively.

You are controlling the hero 00, and your enemy is the hero 11. Each hero has five integer attributes: ATTACK, DEFENSE, POWER, KNOWLEDGE, and HEALTH. When two heroes battle with each other, they will take turns to attack, and your hero moves first. One hero can make exactlyoneattack**exactly one attack** in one turn, either a physical attack or a magical attack.

Assume their attributes are A_iA\_i, D_iD\_i, P_iP\_i, K_iK\_i, H_iH\_i (0i1)0 \leq i \leq 1). For hero ii, its physical attack's damage is C_pmax(1,A_iD_1i)C\_p \cdot \max (1, A\_i - D\_{1-i}), while its magical attack's damage is C_mP_iC\_m \cdot P\_i. Here, C_pC\_p and C_mC\_m are given constants.

After hero ii's attack, H_1iH\_{1-i} will decrease by the damage of its enemy. If H_1iH\_{1-i} is lower or equal to 00, the hero (1i)(1-i) loses, the hero ii wins, and the battle ends.

Hero ii can make magical attacks no more than K_iK\_i times in the whole battle.

Now you know your enemy is a Yog who is utterly ignorant of magic, which means P_1=K_1=0P\_1 = K\_1 = 0, and he will only make physical attacks. You can distribute NN attribute points into four attributes A_0A\_0, D_0D\_0, P_0P\_0, K_0K\_0 arbitrarily, which means these attributes can be any non-negative integers satisfying 0A_0+D_0+P_0+K_0N0 \leq A\_0 + D\_0 + P\_0 + K\_0 \leq N.

Given C_pC\_p, C_mC\_m, H_0H\_0, A_1A\_1, D_1D\_1, and NN, please calculate the maximum H_1H\_1 such that you can build hero 00 and fight so that it wins the game.

입력

The first line contains an integer TT (1T1041 \leq T \leq 10^4), the number of test cases. Then TT test cases follow.

The first and only line of each test case contains six integers C_pC\_p, C_mC\_m, H_0H\_0, A_1A\_1, D_1D\_1, NN (1C_p,C_m,H_0,A_1,D_1,N1061 \leq C\_p, C\_m, H\_0, A\_1, D\_1, N \leq 10^6), the attributes described above.

출력

For each test case, print a line with one integer: the maximum enemy health such that it is possible to win.