CF1994A Diverse Game

题目描述

### 题目大意 给定一个 $n\times m$ 的矩阵 $a$,该矩阵的每个元素都是 $\left[1,n\cdot m\right]$ 内的整数且互不相同。请求出一个矩阵 $b$,满足: - $b$ 的每个元素都是 $\left[1,n\cdot m\right]$ 内的整数且互不相同。 - $\forall 1\le i\le n,1\le j \le m:a_{i,j}\neq b_{i,j}$。

输入格式

第一行包括一个整数 $T$ $\left(1\le T \le10^3\right)$,表示测试用例的数量。 对于每个测试用例: - 第一行包括两个整数 $n,m$ $\left(1\le n,m\le 10\right)$。 - 接下来 $n$ 行包括 $m$ 个整数。其中,第 $i$ 行的 $m$ 个整数分别表示 $a_{i,1},a_{i,2},\dots,a_{i,m}$。 - 输入数据保证矩阵 $a$ 的所有元素互不相同,且 $1\le a_{i,j}\le n\cdot m$。 输入数据保证 $\sum n\cdot m\le5\times10^4$。

输出格式

对于每个测试用例: - 若满足条件的矩阵 $b$ 不存在,输出一个整数 $-1$。 - 否则,输出 $n$ 行,每行包含以空格分隔的 $m$ 个整数。其中,第 $i$ 行的 $m$ 个整数分别表示 $b_{i,1},b_{i,2},\dots,b_{i,m}$。

说明/提示

In the first test case, there is only one element in the matrix, so matrix $ b $ is the only matrix and it does not fit. In the second test case $ a_{1, 1} = 2 \neq 1 = b_{1, 1} $ , $ a_{2, 1} = 1 \neq 2 = b_{2, 1} $ .