#P12676. 相等排列(equal)

相等排列(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.

Problem Description

This problem has TT test cases.

You need to construct nn permutations of length mm such that, for each of the mm numbers, the sum of the indices (indices start from 11) of this number across the nn permutations are all equal. If there is no solution, output 1-1.

Input Format

The first line contains a positive integer TT.

For each test case:

Input one line with two positive integers n,mn, m.

Output Format

For each test case:

Output nn lines, each containing mm positive integers, or output a single line with an integer 1-1 to indicate your answer.

3
3 3
2 5
1 3
1 2 3
2 3 1
3 1 2
5 1 4 2 3
3 2 4 1 5
-1

Hint

For 100%100\% of the testdata, it is guaranteed that 1T1061 \le T \le 10^6, 1n,m1061 \le n, m \le 10^6, nm106\sum nm \le 10^6.

Translated by ChatGPT 5