Ninja and his friends went to a restaurant on the occasion of Ninjaβs birthday. There he was offered by his friends to do some task, if he wins, he would not have to pay a single penny, his friends would pay instead of him. But if he loses, he would have to pay the whole bill. The task was that he was given a bar of chocolate and was asked to break it into single squares.
The rules were as follows:
1.Parts of the chocolate may be broken along the vertical and horizontal lines as indicated by the broken lines in the picture.
2.Each break of a part of the chocolate is charged a cost expressed by a positive integer.
3.This cost does not depend on the size of the part that is being broken but only depends on the line the break goes along.
4.Denoting the costs of breaking along consecutive vertical lines with x1, x2, ..., xm-1 and along horizontal lines with y1, y2, ..., yn-1.
5.The cost of breaking the whole bar into single squares is the sum of the successive breaks.

Now, Ninja has to break the chocolate in such a way that results in minimum cost. So your task is to find the minimum cost.
Input Format :
The first line of input contains βTβ number of test cases.
The first line of each test case contains, input βmβ and βnβ i.e. a number of rows and columns.
The second line of each test contains βm-1β space-separated integer which denotes the horizontal cost.
The third line of each test contains βn-1β space-separated integer which denotes the vertical cost.
Output Format :
For each test case return the minimum cost to breaking the chocolate into a single square.
Note :
You do not need to print anything.It has been already taken care of. Just implement the given function.
Constraints :
1 <= T <= 10
1 <= Xi <= 100
1 <= Yi <= 100
2 <= m,n <= 1000
Where βTβ represents the number of test cases, βx[i]β represents the horizontal cost at βi-thβ index, βy[i]β represents the vertical cost at βi-thβ index, βmβ is a number of rows and βnβ is a number of columns.
Time Limit: 1 second
2
6 4
2 1 3 1 4
4 1 2
2 2
2
4
42
8
Test Case 1:
In the first line, there is the number of test cases i.e. 2 and in the next line, 6 and 4 are the number of rows and columns of the chocolate following the horizontal costs [2,1,3,1,4] and then the vertical costs [4,1,2].
Here, we have started with breaking from the vertical lines that cost 4 and then breaking the two parts from the horizontal line costing 4 and so on.
β4+(4*2)+ (3*2)+(2*3)+(2*3)+(1*4)+(2*4)β = β42β.
Test Case 2:
Here we have 2*2 sizes of chocolate with horizontal cost 2 and vertical cost as 4. If we first divide it at the horizontal cost then the cost would be β2+4*2 = 10β.
While breaking the vertical one first would cost β4+2*2 = 8β
Hence the answer is 8.
2
4 4
4 1 3
2 1 6
3 2
2 1
4
33
10
We would use dynamic programming in this approach i.e. using the previous values for our present solution.
We would use dynamic programming in this approach, i.e., using our present solution's previous values.
Approach:
In this approach, we would take a 2d matrix and would make use of previously stored values.
The algorithm will be:
O(m*n), where m and n are the numbers of horizontal and vertical costs.
As there are nested loops i.e. there is a loop into another loop, the inner loop would iterate n times for each iteration of the outer loop, hence the time complexity would be O(n^2).
O(m*n), where m and n are the numbers of horizontal and vertical costs. It is basically the size of the 2d matrix.
the space required would depend upon the product of the rows and columns.