#P1342A. Road To Zero
Road To Zero
No submission language available for this problem.
Description
You are given two integers and . You can perform two types of operations:
- Pay dollars and increase or decrease any of these integers by . For example, if and there are four possible outcomes after this operation:
- , ;
- , ;
- , ;
- , .
- Pay dollars and increase or decrease both integers by . For example, if and there are two possible outcomes after this operation:
- , ;
- , .
Your goal is to make both given integers equal zero simultaneously, i.e. . There are no other requirements. In particular, it is possible to move from , to .
Calculate the minimum amount of dollars you have to spend on it.
The first line contains one integer () — the number of testcases.
The first line of each test case contains two integers and ().
The second line of each test case contains two integers and ().
For each test case print one integer — the minimum amount of dollars you have to spend.
Input
The first line contains one integer () — the number of testcases.
The first line of each test case contains two integers and ().
The second line of each test case contains two integers and ().
Output
For each test case print one integer — the minimum amount of dollars you have to spend.
Samples
Note
In the first test case you can perform the following sequence of operations: first, second, first. This way you spend dollars.
In the second test case both integers are equal to zero initially, so you dont' have to spend money.