This content is archived!
For the 2018-2019 school year, we have switched to using the WLMOJ judge for all MCPT related content. This is an archive of our old website and will not be updated.Problem
Mark loves watching the Zamboni clean the ice at his local rink. In particular, he’s intrigued by the spiral path the Zamboni takes. The Zamboni starts in the top-left corner of the rectangular rink and follows the longer edge of the rink. Just before it reaches a wall or a previously-cleaned square, it turns 90^\circ clockwise and repeats the process until the rink is entirely clean. Mark wants your help to figure out how many times the Zamboni turns during its path.
Input
The first line of input provides the number of test cases, T (1 \leq T \leq 100). T test cases follow. Each test case consists of one line containing two integers H and W (1 \leq H,W \leq 100), the height and width of the ring. The Zamboni is one unit wide.
Output
For each test case, your program should output one integer, the amount of turns the Zamboni makes.
Sample Input
Sample Output
Explanation for Sample Output
In the first test case, the Zamboni takes the following path:
Editorial
Read only if you are stuck or have already solved the problem.