K-matching

아직 제출이 없습니다시간 제한9초메모리 제한512 MB

문제

Consider a graph GG with nmn \cdot m nodes (i,j)(i, j) (1in1 \leq i \leq n, 1jm1 \leq j \leq m). There is an edge between two nodes (a,b)(a, b) and (c,d)(c, d) if and only if ac+bd=1|a - c| + |b - d| = 1. Each edge has a weight.

Calculate the minimum weight of a KK-matching in GG.

An edge set SS is a matching of G=V,EG = \langle V, E \rangle if and only if each node in VV is connected to at most one edge in SS. A matching SS is a KK-matching if and only if S=K|S| = K. The weight of a matching SS is the sum of the weights of the edges in SS. And finally, the minimum weight KK-matching of GG is defined as the KK-matching of GG with the minimum possible weight.

입력

The first line contains an integer tt, the number of test cases (1t10001 \leq t \leq 1000). It is guaranteed that there are at most 33 test cases with n>100n > 100.

For each test case, the first line contains three integers nn, mm and KK (1n41041 \leq n \leq 4 \cdot 10^4, 1m41 \leq m \leq 4, 1Knm21 \leq K \leq \lfloor \frac{n \cdot m}{2} \rfloor).

Then n1n - 1 lines follow, each of these lines contains mm integers A_i,jA\_{i, j}: the weights of edges between (i,j)(i, j) and (i+1,j)(i + 1, j) (1A_i,j1091 \leq A\_{i, j} \leq 10^9).

If m>1m > 1, then nn more lines follow, each of these lines contains m1m - 1 integers B_i,jB\_{i, j}: the weights of the edge between (i,j)(i, j) and (i,j+1)(i, j + 1) (1B_i,j1091 \leq B\_{i, j} \leq 10^9).

출력

For each test case, print a single line with a single integer: the required minimum weight.