QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#17951. Chocolate and Knight Game (Bitter)

统计

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

Coco wants to play a "G-Knight" game using this chocolate bar and several G-Knights. A G-Knight is a variation of a chess knight that can move $x$ squares horizontally and $y$ squares vertically, or $y$ squares horizontally and $x$ squares vertically 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 bar.

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

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

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

Input

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

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

Output

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

Examples

Input 1

2
5 5 1 1
6 6 1 2

Output 1

15
24

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.