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.
3 2 1 2 1 2 3 1 3 2 2 1 3 3 1 2 3 1 2 3 3 2 1 1 2 3
1 2 1 2 3 1 3 2
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.