


The breaking cost of each edge for the board will be given.
The first line of input contains 'T', the number of test cases.
The first line of each test case contains two space-separated integers 'L' and 'W', denoting the length and width of the box.
The second line contains 'L' - 1 space-separated integer, where the 'ith' integer denotes the cost of one horizontal cut between the rows 'i' and 'i' + 1.
The third line contains 'W' - 1 space-separated integer, where the 'ith' integer denotes the cost of one vertical cut between the columns 'i' and 'i' + 1.
The only line of output of each test case should contain an integer denoting the minimum cost required to break the board into 'L' * 'W' squares.
You don’t need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
2 <= L, W <= 10 ^ 4
1 <= costL[i], costW[i] <= 10 ^ 5
Time Limit: 1 sec
This problem can be solved using the greedy approach. By greedy, we mean that we simply start cutting the board along every horizontal and vertical line. But this cutting needs to be in a specific manner. Let’s see how we can do this.
For example:
L = 3 and W = 3
costL = 1 2 and costW = 2 1