{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eAs we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:\u003cbr\u003e\u003cbr\u003eYuta has a graph $G$ with $n$ nodes $(i,j)(1 \\leq i \\leq n,1 \\leq j \\leq m)$. There is an edge between $(a,b)$ and $(c,d)$ if and only if $|a-c|+|b-d|\u003d1$. Each edge has its weight.\u003cbr\u003e\u003cbr\u003eNow Yuta wants to calculate the minimum weight $K$-matching of $G$.\u003cbr\u003e\u003cbr\u003eIt is too difficult for Rikka. Can you help her?\u0026nbsp;\u0026nbsp;\u003cbr\u003e\u003cbr\u003eAn edge set $S$ is a match of $G\u003d\\langle V,E \\rangle$ if and only if each nodes in $V$ connects to at most one edge in $S$. A match $S$ is a $K$-match if and only if $|S|\u003dK$. The weight of a match $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$-match of $G$ with the minimum weight.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line contains a number $t(1 \\leq t \\leq 1000)$, the number of the testcases. And there are no more than $3$ testcases with $n \u0026gt; 100$.\u003cbr\u003e\u003cbr\u003eFor each testcase, the first line contains three numbers $n,m,K(1 \\leq n \\leq 4 \\times 10^4,1 \\leq m \\leq 4),1 \\leq K \\leq \\lfloor \\frac{nm}{2} \\rfloor$.\u003cbr\u003e\u003cbr\u003eThen $n-1$ lines follow, each line contains $m$ numbers $A_{i,j}(1 \\leq A_{i,j} \u003cbr\u003e\\leq 10^9)$ -- the weight of the edge between $(i,j)$ and $(i+1,j)$.\u003cbr\u003e\u003cbr\u003eIf $m\u0026gt;1$, then $n$ lines follow, each line contains $m-1$ numbers $B_{i,j}(1 \\leq B_{i,j} \\leq 10^9)$ -- the weight of the edge between $(i,j)$ and $(i,j+1)$."}},{"title":"Output","value":{"format":"HTML","content":"For each testcase, print a single line with a single number -- the answer.\u003cbr\u003e\u003cbr\u003eIt is guaranteed that there exists at least one $K$-match."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e3\r\n3 3 1\r\n3 4 5\r\n8 9 10\r\n1 2\r\n6 7\r\n11 12\r\n3 3 2\r\n3 4 5\r\n8 9 10\r\n1 2\r\n6 7\r\n11 12\r\n3 3 3\r\n3 4 5\r\n8 9 10\r\n1 2\r\n6 7\r\n11 12\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e1\r\n5\r\n12\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}