- Time limit: 1.50 s
- Memory limit: 128 MB
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
The first line of the standard input contains a single integer n: 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}, 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.
Output
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.
Constraints
- 1 \le n \le 1000
- 1 \le s_{min} \le s_{max} \le 10^9
- 1 \le w_{min} \le w_{max} \le 10^9
Example
For the input data:
4 3 9 8 8 1 10 11 15 4 7 22 23 2 5 19 24
the correct result is:
8 7 2 5
Explanation: Byteasar will produce four solar panels of the following sizes: 8 \times 8 (a single cell), 7 \times 14 (two cells), 4 \times 22 or 6 \times 22 (22 or 33 cells respectively), and 5 \times 20 (four cells).
Task author: Bartosz Tarnawski.