Preparando MOJI
An array is beautiful if both of the following two conditions meet:
For example, the array $$$[2, 3, 2, 4, 4, 3, 2]$$$ 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 $$$[42, 42, 42]$$$ 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.
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$$$).
For each test case, print one integer — the minimum possible number of elements in a beautiful array.
73 5 4 65 8 5 53 3 10 121 5 3 31 1 2 22 2 1 16 6 6 6
4 5 13 3 3 3 6
Optimal arrays in the test cases of the example: