#SL2310B. Assignment

Assignment

Assignment

You are given two sequences a,ba,b of length nn and a cost matrix AA of size n×nn \times n. The matrix AA satisfies Ai,jAi,j1A_{i,j} \geq A_{i,j-1} for all 1in1 \leq i \leq n, 1<jn1 < j \leq n. You can do the following operation arbitrary number of times:

  • Select three integers l,r,xl,r,x satisfying 1lrn1 \leq l \leq r \leq n and 1xn1 \leq x \leq n, then assign xx to aia_i for all indices ii between ll and rr, inclusive. The cost of this operation is Ax,rl+1A_{x,r-l+1}.

For all i[0,k]i \in [0,k], find the minimum sum of costs to make aa has at most ii positions differing from bb.

Input

The first line contains a single integer T(1T10)T \: (1 \leq T \leq 10), denoting the number of test cases.

For each test case, the first line contains two integers n,k(1n100,1k10)n, k \: (1 \leq n \leq 100, 1 \leq k \leq 10).

The second line contains nn integers a1,a2,,an(1ain)a_1, a_2, \dots , a_n \: (1 \leq a_i \leq n), denoting the sequence aa.

The third line contains nn integers b1,b2,,bn(1bin)b_1,b_2,\dots,b_n(1 \leq b_i \leq n), denoting the sequence bb.

The next nn lines, each contains nn integers. The jj-th integer in the ii-th line denotes Ai,j(1Ai,j106)A_{i,j} \: (1 \leq A_{i,j} \leq 10^6).

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 k+1k + 1 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