QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 128 MB Total points: 100 Difficulty: [show]

#309. Solar Panels

Statistics

Having decided to invest in renewable energy, Byteasar started a solar panels factory. It appears that he has hit the gold as within a few days $n$ clients walked through his door. Each client has ordered a single rectangular panel with specified width and height ranges.

The panels consist of square photovoltaic cells. The cells are available in all integer sizes, i.e., with the side length integer, but all cells in one panel have to be of the same size. The production process exhibits economies of scale in that the larger the cells that form it, the more efficient the panel. Thus, for each of the ordered panels, Byteasar would like to know the maximum side length of the cells it can be made of.

Input Format

The first line of the standard input contains a single integer $n$ ($1 ≤ n ≤ 1\,000$): the number of panels that were ordered. The following n lines describe each of those panels: the $i$-th line contains four integers $s_{min}$, $s_{max}$, $w_{min}$, $w_{max}$ ($1 ≤ s_{min} ≤ s_{max} ≤ 10^{9}$, $1 ≤ w_{min} ≤ w_{max} ≤ 10^{9}$), separated by single spaces; these specify the minimum width, the maximum width, the minimum height, and the maximum height of the i-th panel respectively.

In tests worth $75\%$ of the total score, $s_{max},w_{max} ≤ 10^{7}$ holds for each panel. In their subset worth $20\%$ of the total score, $n ≤ 10$ holds in addition.

Output Format

Your program should print exactly $n$ lines to the standard output. The $i$-th line is to give the maximum side length of the cells that the $i$-th panel can be made of.

Example

Input

4
3 9 8 8
1 10 11 15
4 7 22 23
2 5 19 24

Output

8
7
2
5

Byteasar will produce four solar panels of the following sizes: 8x8(a single cell), 7x14(two cells), 4x22 or 6x22 (22 or 33 cells respectively), and 5x20 (four cells).

Discussions

About Discussions

The discussion section is only for posting: Editorials, 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. Submitting multiple issues may cause your account to be banned.
  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.