Kotlin Heroes: Episode 11 |
---|
Finished |
You are given a matrix $$$a$$$ of size $$$n \times m$$$, consisting of integers from $$$0$$$ to $$$31$$$ inclusive.
Let's call the matrix strange if for every two distinct rows $$$i$$$ and $$$j$$$, both of the following conditions hold:
You can perform the following operation any number of times: take any row of the matrix and a number $$$y$$$ from $$$0$$$ to $$$31$$$ inclusive; then apply the bitwise XOR with the number $$$y$$$ to all elements of the selected row. The cost of such an operation is equal to $$$y$$$.
Your task is to calculate the minimum cost to make the matrix strange, or report that it is impossible.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases.
The first line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le n, m \le 50$$$; $$$1 \le k \le m$$$).
Next, there are $$$n$$$ lines, the $$$i$$$-th of which contains $$$m$$$ integers $$$a_{i, 1}, a_{i, 2}, \dots, a_{i, m}$$$ ($$$0 \le a_{i, j} \le 31$$$).
For each test case, output one integer — the minimum cost to make the matrix strange, or -1 if it is impossible to make the matrix strange.
32 3 10 1 01 0 13 2 20 12 34 55 5 50 5 17 4 228 5 16 21 97 25 31 30 80 0 5 15 131 2 3 4 5
30 -1 24
Name |
---|