Types of burgers
82% Success1559 Attempts30 Points2s Time Limit256MB Memory1024 KB Max Code

Bob sells burgers with three different combinations, $$B_1$$, $$B_2$$ and $$B_3$$. There are total $$X$$, $$Y$$, and $$Z$$ burgers with combinations, $$B_1$$, $$B_2$$, and $$B_3$$ respectively. Each burger has an integer value called deliciousness as follows:

  • The deliciousness of the burgers with the $$B_1$$ combination are \(B_{11}, B_{12}, B_{13}, .... , B_{1X}\).
  • The deliciousness of the burgers with the $$B_2$$ combination are \(B_{21}, B_{22}, B_{23}, .... , B_{2Y}\).
  • The deliciousness of the burgers with the $$B_3$$ combination are \(B_{31}, B_{32}, B_{33}, .... , B_{3Z}\).

Alice decides to buy $$K$$ boxes containing three burgers, one from each of the combinations. The deliciousness of a box is the sum of the deliciousness of the burgers present inside it.

There are \(X*Y*Z\) such ways to select a box. Print the maximum total sum of deliciousness that Alice can get by buying $$K$$ boxes.

Input format

  • The first line contains an integer $$T$$ denoting the number of test cases.
  • The first line of each test case contains three space-separated integers $$X$$, $$Y$$, and $$Z$$.
  • The second line of each test case contains a single integer $$K$$.
  • The third line of each test case contains $$X$$ space-separated integers denoting array $$B_{1i}$$.
  • The fourth line of each test case contains $$Y$$ space-separated integers denoting array $$B_{2j}$$.
  • The fifth line of each test case contains $$Z$$ space-separated integers denoting array $$B_{3k}$$.

Output format

For each test case, print the maximum total sum of deliciousness that Alice can get by buying $$K$$ boxes in a new line.

Constraints

\(1 \le T \le 10\)
\(1 \le X,Y,Z \le 1000\)
\(1 \le K \le min(3000,X*Y*Z)\)
\(1 \le B_{1i},B_{2j},B_{3k} \le 1000000000\)

Examples
Input
2
2 2 2 
7
4 6
1 5
3 8
6 3 2
32
6 9 8 8 1 8
5 7 3
9 3
Output
100
597
Explanation

For the first testcase, the combinations of burger in the boxes are \((B_{11},B_{21},B_{32}),(B_{11},B_{22},B_{31}),(B_{11},B_{22},B_{32}),(B_{12},B_{21},B_{31}),(B_{12},B_{21},B_{32}),(B_{12},B_{22},B_{31})\ and\ (B_{12},B_{22},B_{32})\). Thus, the total sum of deliciousness Alice can buy is $$100$$.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading Editor...
Results