#P1401B. Ternary Sequence
Ternary Sequence
No submission language available for this problem.
Description
You are given two sequences and . Each element of both sequences is either , or . The number of elements , , in the sequence is , , respectively, and the number of elements , , in the sequence is , , respectively.
You can rearrange the elements in both sequences and however you like. After that, let's define a sequence as follows:
$c_i = \begin{cases} a_i b_i & \mbox{if }a_i > b_i \\ 0 & \mbox{if }a_i = b_i \\ -a_i b_i & \mbox{if }a_i < b_i \end{cases}$
You'd like to make (the sum of all elements of the sequence ) as large as possible. What is the maximum possible sum?
The first line contains one integer () — the number of test cases.
Each test case consists of two lines. The first line of each test case contains three integers , , () — the number of -s, -s and -s in the sequence .
The second line of each test case also contains three integers , , (; ) — the number of -s, -s and -s in the sequence .
For each test case, print the maximum possible sum of the sequence .
Input
The first line contains one integer () — the number of test cases.
Each test case consists of two lines. The first line of each test case contains three integers , , () — the number of -s, -s and -s in the sequence .
The second line of each test case also contains three integers , , (; ) — the number of -s, -s and -s in the sequence .
Output
For each test case, print the maximum possible sum of the sequence .
Samples
Note
In the first sample, one of the optimal solutions is:
In the second sample, one of the optimal solutions is:
In the third sample, the only possible solution is: