## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## [Solution] Minimums and Maximums Codeforces Solution | Codeforces Problem Solution 2022

A. Minimums and Maximums
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

An array is beautiful if both of the following two conditions meet:

• there are at least ${l}_{1}$ and at most ${r}_{1}$ elements in the array equal to its minimum;
• there are at least ${l}_{2}$ and at most ${r}_{2}$ elements in the array equal to its maximum.

For example, the array $\left[2,3,2,4,4,3,2\right]$ has $3$ elements equal to its minimum ($1$-st, $3$-rd and $7$-th) and $2$ elements equal to its maximum ($4$-th and $5$-th).

Another example: the array $\left[42,42,42\right]$ has $3$ elements equal to its minimum and $3$ elements equal to its maximum.

Your task is to calculate the minimum possible number of elements in a beautiful array.

Input

The first line contains one integer $t$ ($1\le t\le 5000$) — the number of test cases.

Each test case consists of one line containing four integers ${l}_{1}$${r}_{1}$${l}_{2}$ and ${r}_{2}$ ($1\le {l}_{1}\le {r}_{1}\le 50$$1\le {l}_{2}\le {r}_{2}\le 50$).

Output

For each test case, print one integer — the minimum possible number of elements in a beautiful array.