CF2060B.Farmer John's Card Game

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Farmer John's Card Game

Farmer John's nn cows are playing a card game! Farmer John has a deck of nmn \cdot m cards numbered from 00 to nm1n \cdot m-1. He distributes mm cards to each of his nn cows.

Farmer John wants the game to be fair, so each cow should only be able to play 11 card per round. He decides to determine a turn order, determined by a permutation^{\text{∗}} pp of length nn, such that the pip_i'th cow will be the ii'th cow to place a card on top of the center pile in a round.

In other words, the following events happen in order in each round:

  • The p1p_1'th cow places any card from their deck on top of the center pile.
  • The p2p_2'th cow places any card from their deck on top of the center pile.
  • ...
  • The pnp_n'th cow places any card from their deck on top of the center pile.

There is a catch. Initially, the center pile contains a card numbered 1-1. In order to place a card, the number of the card must be greater than the number of the card on top of the center pile. Then, the newly placed card becomes the top card of the center pile. If a cow cannot place any card in their deck, the game is considered to be lost.

Farmer John wonders: does there exist pp such that it is possible for all of his cows to empty their deck after playing all mm rounds of the game? If so, output any valid pp. Otherwise, output 1-1.

^{\text{∗}}A permutation of length nn contains each integer from 11 to nn exactly once

Input

The first line contains an integer tt (1t4001 \leq t \leq 400) — the number of test cases.

The first line of each test case contains two integers nn and mm (1nm20001 \leq n \cdot m \leq 2\,000) — the number of cows and the number of cards each cow receives.

The following nn lines contain mm integers each – the cards received by each cow. It is guaranteed all given numbers (across all nn lines) are distinct and in the range from 00 to nm1n \cdot m - 1, inclusive.

It is guaranteed the sum of nmn \cdot m over all test cases does not exceed 20002\,000.

Output

For each test case, output the following on a new line:

  • If pp exists, output nn space-separated integers p1,p2,,pnp_1, p_2, \ldots, p_n.
  • Otherwise, output 1-1.

Note

In the first test case, one turn order that allows all cards to be played is by having the first cow go before the second cow. The cards played will be $0\rightarrow1\rightarrow2\rightarrow3\rightarrow4\rightarrow5$.

In the second test case, there is only one cow, so having the cow play all of her cards in increasing order will empty the deck.

In the third test case, it can be shown there is no valid turn order that allows all cards to be played.

Samples

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

在线编程 IDE

建议全屏模式获得最佳体验