Consider a graph G with n⋅m nodes (i,j) (1≤i≤n, 1≤j≤m). There is an edge between two nodes (a,b) and (c,d) if and only if ∣a−c∣+∣b−d∣=1. Each edge has a weight.
Calculate the minimum weight of a K-matching in G.
An edge set S is a matching of G=⟨V,E⟩ if and only if each node in V is connected to at most one edge in S. A matching S is a K-matching if and only if ∣S∣=K. The weight of a matching S is the sum of the weights of the edges in S. And finally, the minimum weight K-matching of G is defined as the K-matching of G with the minimum possible weight.
The first line contains an integer t, the number of test cases (1≤t≤1000). It is guaranteed that there are at most 3 test cases with n>100.
For each test case, the first line contains three integers n, m and K (1≤n≤4⋅104, 1≤m≤4, 1≤K≤⌊2n⋅m⌋).
Then n−1 lines follow, each of these lines contains m integers A_i,j: the weights of edges between (i,j) and (i+1,j) (1≤A_i,j≤109).
If m>1, then n more lines follow, each of these lines contains m−1 integers B_i,j: the weights of the edge between (i,j) and (i,j+1) (1≤B_i,j≤109).
For each test case, print a single line with a single integer: the required minimum weight.