
The number of items in a bag must remain constant before and after swapping.
Any number of swappings is permitted.
It is guaranteed that there is at least one way to make the values of all the bags equal to each other.
The first line contains an integer ‘T’, which denotes the number of test cases or queries to be run. Then, the ‘T’ test cases follow.
The first line of each test case contains an integer ‘N’, denoting the total number of bags. The next 2*’N’ lines contain the following :
The first line contains a single integer ‘M’, denoting the number of items in the bag.
The second line contains ‘M’ space-separated integers, denoting the value of each item in the bag.
For each test case, print in a new line the contents of every bag in non-decreasing order.
Output for each test case will be printed in a separate line.
The contents of all the bags must be printed in separate lines, and the following rules must be followed :
The contents of the bag that contains the item having the least value must be printed on the first line.
The contents of the bag that contains the item having the second least value must be printed on the second line and so on and so forth.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N,M <= 10
1 <= X <= 10^4
Where 'X' is the value of any item in any bag
Time Limit: 1sec
Approach:
The approach is to find out the required value for each bag. We need to store the sizes of all the bags and the values of all the items. Then for each size, we can find out these many values that can sum up to the required weight for each bag. We can keep doing this for all bags and finally when we get our result, we can simply sort the contents in the required order and return the values.