Under construction

Still being built. Things may change

Chocolate and ㄱ나이트 Game (Bitter)

Time limit2sMemory limit1024 MB

Summary
Given a X by Y board and knight moves of (±x, ±y), find the maximum number of knights that can be placed so none can attack another.
Level

Medium7 of 10

Topics
Math, Graph, Combinatorics
Solved
No attempts yet

Problem

Coco has a rectangular chocolate bar with width XX and height YY. The bar is divided into 1×11\times 1 unit squares.

Coco wants to play the ㄱ나이트 game with this chocolate and several ㄱ나이트 pieces. A ㄱ나이트 is a variant of the chess knight. In one move, it can go to a square xx squares to the right or left and yy squares up or down from its current square. A ㄱ나이트 ignores the other pieces while it moves. If the destination is outside the chocolate, the piece cannot move there.

The ㄱ나이트 game is played by placing as many ㄱ나이트 pieces as possible on the chocolate under these rules:

  • A square can hold at most one ㄱ나이트.
  • If a ㄱ나이트 can move in one move to a square, that square must not hold another ㄱ나이트.
  • The chocolate cannot be flipped or rotated.

Find the maximum number of ㄱ나이트 pieces that Coco can place on the chocolate.

Input

The first line contains the number of test cases TT. (1≤T≤100 000)(1\le T\le 100\,000)

Each test case is given on one line with four integers XX, YY, xx, and yy, separated by spaces. (1≤X,Y,x,y≤109)(1\le X,Y,x,y\le 10^9)

Output

For each test case, print the maximum number of ㄱ나이트 pieces that can be placed on the chocolate, one per line.

Examples1

  1. Example 1

    Input
    4
    4 4 1 1
    5 5 1 1
    6 6 1 2
    10 10 50 50
    
    Expected output
    8
    15
    24
    100