A radio station broadcasts a countdown chart: a fixed list of singles that must be played in a given order, from the least popular to the most popular. Each single has a known length in whole minutes.
The broadcast is divided into equal blocks of $M$ minutes (every hour a few minutes are reserved for commercials and news, so a block is shorter than a full hour). The singles are handed to the blocks in order: each block receives a contiguous run of singles from the list, no single is split across two blocks, and every single is played in exactly one block. The number of blocks is not fixed, but it must be a whole number, and every block must be complete — together the blocks must contain all of the singles.
The singles assigned to a block rarely add up to exactly $M$ minutes.
Thus, for a block whose singles have total length $L$ minutes, the penalty is $A \cdot (L - M)$ when $L > M$, $B \cdot (M - L)$ when $L < M$, and $0$ when $L = M$.
Schedule all the singles into blocks so that the total penalty, summed over every block, is as small as possible.
The first line contains a single integer $T$: the number of test cases. Each test case consists of three lines.
For each test case, print a single line with one integer: the minimum possible total penalty for scheduling that chart.