There are \(N\) shops each selling \(M\) different kinds of items. The \(i\)th store sells the \(j\)th item for \(C\)ij dollars. You decide to buy \(M-1\) different type of items from each shop. If you want to have all \(M\) kinds of items in your shopping bag, then what is the minimum amount that you need to spend?
Input format
Output format
For each test case, print the minimum cost required as described in the problem statement in a new line. Print -1 if it is not possible to have all \(M\) different kinds of items.
Constraints
$$1$$ \(\leq\) \(T\) \(\leq\) $$10$$
$$1$$ \(\leq\) \(N\) \(\leq\) $$1000$$
$$1$$ \(\leq\) \(M\) \(\leq\) $$1000$$
$$1$$ \(\leq\) \(C\)ij \(\leq\) $$10^9$$
We can buy 1st and 2nd items from shop 01, 2nd and 3rd item from shop 02 and 1st and 2nd items from shop 03.
Hence the total sum is (2 + 3) + (2 + 5) + (4 + 4) = 5 + 7 + 8 = 20 dollars