#SL2310B. Assignment
Assignment
Assignment
You are given two sequences of length and a cost matrix of size . The matrix satisfies for all , . You can do the following operation arbitrary number of times:
- Select three integers satisfying and , then assign to for all indices between and , inclusive. The cost of this operation is .
For all , find the minimum sum of costs to make has at most positions differing from .
Input
The first line contains a single integer , denoting the number of test cases.
For each test case, the first line contains two integers .
The second line contains integers , denoting the sequence .
The third line contains integers , denoting the sequence .
The next lines, each contains integers. The -th integer in the -th line denotes .
It is guaranteed that for all $1 \leq i \leq n, 1 < j \leq n, A_{i,j} \geq A_{i,j-1}$.
Output
For each test case, output one line with integers denoting the answer
Example
1
5 2
1 5 3 2 2
2 4 5 4 2
3 3 3 4 4
2 2 3 4 5
3 4 5 6 7
1 1 1 2 4
4 5 5 5 5
7 3 1