P12676 Equal Permutations (equal).
Background
~~This problem was planned to redesign part of the scoring in early July.~~
Due to personal reasons, it is planned to be postponed.
Description
This problem has $T$ test cases.
You need to construct $n$ permutations of length $m$ such that, for each of the $m$ numbers, the sum of the indices (indices start from $1$) of this number across the $n$ permutations are all equal. If there is no solution, output $-1$.
Input Format
The first line contains a positive integer $T$.
For each test case:
Input one line with two positive integers $n, m$.
Output Format
For each test case:
Output $n$ lines, each containing $m$ positive integers, or output a single line with an integer $-1$ to indicate your answer.
Explanation/Hint
For $100\%$ of the testdata, it is guaranteed that $1 \le T \le 10^6$, $1 \le n, m \le 10^6$, $\sum nm \le 10^6$.
Translated by ChatGPT 5