CF2044C.Hard Problem

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Hard Problem

Ball is the teacher in Paperfold University. The seats of his classroom are arranged in 22 rows with mm seats each.

Ball is teaching a+b+ca + b + c monkeys, and he wants to assign as many monkeys to a seat as possible. Ball knows that aa of them only want to sit in row 11, bb of them only want to sit in row 22, and cc of them have no preference. Only one monkey may sit in each seat, and each monkey's preference must be followed if it is seated.

What is the maximum number of monkeys that Ball can seat?

Input

The first line contains an integer tt (1t1041 \leq t \leq 10^4) — the number of test cases.

Each test case contains four integers mm, aa, bb, and cc (1m,a,b,c1081 \leq m, a, b, c \leq 10^8).

Output

For each test case, output the maximum number of monkeys you can seat.

Note

In the second test case, 66 monkeys want to sit in the front row, but only 33 seats are available. The monkeys that have no preference and the monkeys who prefer sitting in the second row can sit in the second row together. Thus, the answer is 3+2=53+2=5.

Samples

5
10 5 5 10
3 6 1 1
15 14 12 4
1 1 1 1
420 6 9 69
20
5
30
2
84

在线编程 IDE

建议全屏模式获得最佳体验