Codeforces Round 1010 (Div. 2, Unrated)
E
Quaternary Matrix
Codeforces
未评级
原题
← DF →
翻译中…

A matrix is called quaternary if all its elements are $0$, $1$, $2$, or $3$.

翻译中…

Ecrade calls a quaternary matrix $A$ good if the following two properties hold.

翻译中…
  • The bitwise XOR of all numbers in each row of matrix $A$ is equal to $0$.
  • The bitwise XOR of all numbers in each column of matrix $A$ is equal to $0$.
翻译中…

Ecrade has a quaternary matrix of size $n \times m$. He is interested in the minimum number of elements that need to be changed for the matrix to become good, and he also wants to find one of the possible resulting matrices.

翻译中…

However, it seems a little difficult, so please help him!

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2 \cdot 10^5$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 10^3$).

翻译中…

This is followed by $n$ lines, each containing exactly $m$ characters and consisting only of $0$, $1$, $2$, and $3$, describing the elements of Ecrade's matrix.

翻译中…

It is guaranteed that the sum of $n\cdot m$ over all test cases does not exceed $10^6$.

翻译中…

Output

翻译中…

For each test case, print the minimum number of elements that need to be changed for the matrix to become good on the first line, then print $n$ lines, each containing exactly $m$ characters and consisting only of $0$, $1$, $2$, and $3$, describing one of the possible resulting matrices.

翻译中…

If there are multiple possible resulting matrices, output any of them.

翻译中…

样例

Input #1
5
3 3
313
121
313
3 3
000
000
000
4 4
0123
1230
2301
3012
4 4
1232
2110
3122
1311
4 4
1232
2110
3122
1312
Output #1
3
213
101
312
0
000
000
000
0
0123
1230
2301
3012
6
0132
2310
3131
1313
5
0132
2310
3120
1302
InputCopy OutputCopy
题目信息
题号
2082E
时间限制
2 s
内存限制
512 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。