QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 1024 MB Points totaux : 100 Hackable ✓

#17940. Chocolate and Knight Game (Sweet)

Statistiques

Coco has a rectangular chocolate bar with width $X$ and height $Y$. This chocolate is divided into $1 \times 1$ unit squares.

Coco wants to play a "G-Knight" game with this chocolate and several G-Knights. A G-Knight is a variation of a chess knight that can move $x$ squares to the right and $y$ squares down in a single move. G-Knights are not obstructed by other pieces when moving. A G-Knight cannot move to a square that is outside the boundaries of the chocolate.

The G-Knight game is about placing as many G-Knights as possible on the chocolate while following these rules:

  • At most one G-Knight can be placed on any single square of the chocolate.
  • No G-Knight can be placed on a square that another G-Knight can reach in a single move.
  • The chocolate cannot be flipped or rotated.

Calculate the maximum number of G-Knights Coco can place on the chocolate.

Input

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

For each test case, the width $X$ and height $Y$ of the chocolate, and the values $x$ and $y$ representing the movement rule of the G-Knight, are given in order on a single line, separated by spaces. $(1 \le X, Y, x, y \le 50)$

Output

For each test case, output the maximum number of G-Knights that can be placed on the chocolate on a single line.

Examples

Input 1

2
5 5 1 1
10 10 50 50

Output 1

15
100

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.