JDCC '15 Contest 2 P2 - Icy Spiral

View as PDF

Submit solution


Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

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 degrees 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 Specification

The first line of input provides the number of test cases, T (1 \le T \le 100). T test cases follow. Each test case consists of one line containing two integers H and W (1 \le H,W \le 100), the height and width of the ring. The Zamboni is one unit wide.

Output Specification

For each test case, your program should output one integer, the amount of turns the Zamboni makes.

Sample Input

2
3 5
4 4

Sample Output

4
6

Explanation for Sample Input

In the first test case, the Zamboni takes the following path:


Comments

There are no comments at the moment.