CF1790C.Premutation

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A sequence of nn numbers is called permutation if it contains all integers from 11 to nn exactly once. For example, the sequences [ 3,1,4,23, 1, 4, 2 ], [ 11 ] and [ 2,12,1 ] are permutations, but [ 1,2,11,2,1 ], [ 0,10,1 ] and [ 1,3,41,3,4 ] — are not.

Kristina had a permutation pp of nn elements. She wrote it on the whiteboard nn times in such a way that:

  • while writing the permutation at the ii -th ( 1in)1 \le i \le n) time she skipped the element pip_i

So, she wrote in total nn sequences of length n1n-1 each.For example, suppose Kristina had a permutation pp = [4,2,1,3][4,2,1,3] of length 44 . Then she did the following:

  1. Wrote the sequence [2,1,3][2, 1, 3] , skipping the element p1=4p_1=4 from the original permutation.
  2. Wrote the sequence [4,1,3][4, 1, 3] , skipping the element p2=2p_2=2 from the original permutation.
  3. Wrote the sequence [4,2,3][4, 2, 3] , skipping the element p3=1p_3=1 from the original permutation.
  4. Wrote the sequence [4,2,1][4, 2, 1] , skipping the element p4=3p_4=3 from the original permutation.

You know all nn of sequences that have been written on the whiteboard, but you do not know the order in which they were written. They are given in arbitrary order. Reconstruct the original permutation from them.

For example, if you know the sequences [4,2,1][4, 2, 1] , [4,2,3][4, 2, 3] , [2,1,3][2, 1, 3] , [4,1,3][4, 1, 3] , then the original permutation will be pp = [4,2,1,3][4, 2, 1, 3] .

输入格式

The first line of input data contains a single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases.

The description of the test cases follows.

The first line of each test case contains one integer nn ( 3n1003 \le n \le 100 ).

This is followed by nn lines, each containing exactly n1n-1 integers and describing one of the sequences written out on the whiteboard.

It is guaranteed that all sequences could be obtained from some permutation pp , and that the sum n2n^2 over all input sets does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, output on a separate line a permutation pp such that the given nn sequences could be obtained from it.

It is guaranteed that the answer exists and it is the only one. In other words, for each test case the required permutation is sure to exist.

输入输出样例

  • 输入#1

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

    输出#1

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

说明/提示

The first test case is described in the problem statement.

In the second test case, the sequences are written in the correct order.

首页