In her bakery, Bessie has an oven that can produce a cookie in units of time or a muffin in units of time. Due to space constraints, Bessie can only produce one pastry at a time, so to producecookies andmuffins, it takesunits of time.
Bessie’sfriends would each like to visit the bakery one by one. The-th friend will ordercookies andmuffins immediately upon entering. Bessie doesn’t have space to store pastries, so she only starts making pastries upon receiving an order. Furthermore, Bessie’s friends are very busy, so the-th friend is only willing to waitunits of time before getting sad and leaving.
Bessie really does not want her friends to be sad. With one mooney, she can upgrade her oven so that it takes one less unit of time to produce a cookie or one less unit of time to produce a muffin. She can’t upgrade her oven a fractional amount of times, but she can choose to upgrade her oven as many times as she needs before her friends arrive, as long as the time needed to produce a cookie and to produce a muffin both remain strictly positive.
For each oftest cases, please help Bessie find out the minimum amount of moonies that Bessie must spend so that her bakery can satisfy all of her friends.
输入格式
The first line contains, the number of test cases.
Each test case starts with one line containing ,,. Then, the nextlines each contain three integers.
Consecutive test cases are separated by newlines.
输出格式
The minimum amount of moonies that Bessie needs to spend for each test case, on separate lines.
In the first test case, Bessie can paymoonies to decrease the time required to produce a cookie byand a muffin by, so that her oven produces cookies inunits of time and muffins inunits of time. Then she can satisfy the first friend inunits of time, the second friend inunits of time, and the third friend inunits of time, so none of them will get sad and leave.
In the second test case, Bessie should decrease the time required to produce a cookie byand a muffin by.