One of the most important activities on the beach is sunbathing, trying to get that perfect tan. If Roger does not put on any suncream his skin will burn, but if he puts on too much the suncream will block the rays of the sun. Help Roger optimize the use of his suncream.
At each minute, Roger has the option of putting on more suncream, causing his current sun protection factor (SPF) to equal that of the suncream. If he does not put on any suncream, his SPF decreases by one compared to the previous minute, until it reaches . Roger has an ideal sun protection factor , and the benefit to his skin of one minute of sunbathing is given by the following function, where is Roger’s current SPF:
An integer denoting the number of test cases. Each test case consists of four integers , where is the number of minutes that Roger will sunbathe, is the sun protection factor of the suncream, is Roger’s ideal SPF, and is the suncream quantity (the number of times that Roger can put on more suncream).
For each test case, a single line with an integer number representing the maximum total benefit that Roger can achieve to his skin.
In the first example, the maximum benefit is achieved by applying suncream at the first and third minute. In the second example, Roger’s ideal SPF is , so he should never put on suncream. In the third example, Roger has no suncream available, so he cannot apply any. In the fourth example, the maximum benefit is achieved by applying suncream at the first minute.
Input
4 4 10 10 2 4 10 0 3 4 10 10 0 4 10 5 3
Output
3998 4000 3600 3946