404982: GYM101726 E Election in Yekaterinburg

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

E. Election in Yekaterinburgtime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Yekaterinburg, Russia, is a city with a curious voting system. In an election in which there are V spots for a job, each voter has the right to cast up to V votes, ordered by his preference.

The candidates with the most votes, ignoring the order of preference, are elected. Only when there is a tie that the ordering is relevant. In that case, the candidate with most votes for first position wins. If the tie persists, the candidate with most votes for the second position wins, and so on.

In the case that two or more candidates are still tied after accounting all positions, all are elected, even if it exceeds the number of jobs. Candidates with zero votes can be elected if there are still vacancies.

Your task is to manage an election in Yekaterinburg.

Input

The first line contains a single integer, T, the number of test cases.

The first line of each test case has 3 integers, N, K and V, the number of voters, candidates, and job vacancies, respectively. Each of the next N lines begins with a begins with a number Li, the number of candidates the voter i will vote for, and then Li integers, the votes. Candidates are numbered from 1 to K.

If the vote is not for a valid, that is, outside the interval [1, K], then it is counted as a blank vote. If a voter votes more than V times, only the first V votes should be considered.

Limits

  • 1 ≤ T ≤ 105
  • 1 ≤ N ≤ 105
  • 1 ≤ V ≤ K ≤ 100
  • 0 ≤ Li ≤ 100
  • The sum of N over all test cases will not exceed 3·105.
  • The sum of Li over all test cases will not exceed 3·105.
Output

For each test case, print in a single line the list of all elected candidates, ordered by their classification. If two or more candidates are in a tie, order them by their indices.

ExampleInput
2
5 3 2
2 1 3
2 2 3
2 1 3
2 2 3
1 1
3 6 3
3 1 5 3
3 1 0 3
3 1 4 5
Output
3 1
1 5 3

Source/Category

加入题单

算法标签: