Might and Magic
시간 제한2초메모리 제한512 MB
주어진 능력치 예산으로 물리 공격만 하는 적을 이길 수 있을 때, 이길 수 있는 적 체력의 최댓값을 구한다.
문제
Two heroes are fighting, whose names are hero and hero respectively.
You are controlling the hero , and your enemy is the hero . 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 in one turn, either a physical attack or a magical attack.
Assume their attributes are , , , , (. For hero , its physical attack's damage is , while its magical attack's damage is . Here, and are given constants.
After hero 's attack, will decrease by the damage of its enemy. If is lower or equal to , the hero loses, the hero wins, and the battle ends.
Hero can make magical attacks no more than times in the whole battle.
Now you know your enemy is a Yog who is utterly ignorant of magic, which means , and he will only make physical attacks. You can distribute attribute points into four attributes , , , arbitrarily, which means these attributes can be any non-negative integers satisfying .
Given , , , , , and , please calculate the maximum such that you can build hero and fight so that it wins the game.
입력
The first line contains an integer (), the number of test cases. Then test cases follow.
The first and only line of each test case contains six integers , , , , , (), 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.