Gifts! Gifts! Gifts!
Submissions: 543   Accuracy:


  Difficulty: Easy   Marks: 2

There is an orphanage which offers home to hundreds of children who have no parents. They are given gifts on the birthday of the owner. However the orphanage has its own unique way of distributing gifts. Exactly one gift is bought for every child. All the children are then told to submit a list of gifts ordered according to their preference. The children were then given ranks based on their behaviour throughout the year. The gifts were then distributed based on the ranks of the children and their preferences. In other words, the preference of a child with a better rank was given more importance. The task is to write a program that tells about the gifts which children get.


The first line of input takes an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two input lines.
The first line of each test case takes an integer N denoting the number of children, which is also equal to the number of gifts.
The second line of each test case takes N*N space separated integers, the first N integers denoting the choices filled in by child with rank 1, the second N integers denoting the choices filled in by child with rank 2 and so on.

Corresponding to each test case, print N space separated integers, ith integer denoting the gift received by child with rank i.




1 2 1 2
1 3 2 2 1 3 3 1 2
1 2 3 3 2 1 1 2 3


1 2 
1 2 3 
1 3 2

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Arpan Kundu
Author: akundusaltlake

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.