|
||||||||||
Halt HaterTime Limit: 8000/4000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 355 Accepted Submission(s): 148 Problem Description Cuber QQ has recently won a million dollars and bought a new car. He is now driving in the Infinite City and he doesn't want his car to stop, ever! The Infinite City, looks like an infinite grid, with infinite streets built at all possible $x$'s and $y$'s when they are integers. The following picture, looks like part of this city. (The picture is downloaded from a webpage, which is certainly not describing the Infinite City.) There are traffic lights installed on every crossings. Just like what Chinese people usually do, the traffic lights only show signals for left and straight and you can always turn right regardless of the traffic light. The estimate time of waiting for a left turn is $a$, at all crossings; and the time of waiting for a straight is $b$. Cuber QQ is now driving from $(0, -1)$ to $(0, 0)$, about to entering the crossing at $(0, 0)$. At a crossing, he can choose to go straight, turn left or turn right. He wishes to go to $(x, y)$, but here is a weird request: he wants to have the least estimated traffic light waiting time. In other words, he doesn't care whether he has to drive a long way, or he has to burn a lot of gas, all he wants is to wait as little as possible. Note that Cuber QQ doesn't have to wait for the traffic light at $(x, y)$; he also doesn't care from which direction he enters $(x, y)$. Input The first line of the input contains an integer $t$ ($1 \le t \le 100~000$). Then follows $t$ test cases, each containing $a$, $b$, $x$, $y$ ($1 \le a, b \le 10^9$, $-10^9 \le x, y \le 10^9$, $|x| + |y| > 0$), space separated. Output For each test case, output one integer as the answer. Sample Input
Sample Output
Source | ||||||||||
|