F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Halt Hater

Time 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
4 9 1 0 2 2 1 8 0 2 3 3 3 1 1 -1 -1
 

Sample Output
2 7 6 1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 16:51:02, Gzip enabled