#K90602. Successful Teams

    ID: 37789 Type: Default 1000ms 256MiB

Successful Teams

Successful Teams

You are given several test cases. In each test case you are provided with the total number of teams n, a maximum allowed submission time k (in minutes), and a list of submissions. Each submission consists of a team ID and the submission time (in minutes). Your task is to determine, for each test case, which teams made at least one submission within the allowed time \(k\). The resulting list of team IDs for each test case must be printed in increasing order.

Input Constraints and Format:
For each test case, the first line contains three integers: \(n\) (the number of teams), \(k\) (the maximum allowed submission time), and \(m\) (the number of submissions). The next \(m\) lines each contain two integers representing a team ID and its submission time. It is guaranteed that team IDs are positive integers.

Note: If a team has multiple submissions, it only needs one submission within the allowed time to be considered successful.

inputFormat

The first line of the input contains a single integer \(T\) indicating the number of test cases. For each test case, the first line contains three space-separated integers: \(n\), \(k\), and \(m\) — the number of teams, the maximum allowed submission time, and the number of submissions respectively. The next \(m\) lines each contain two integers: the team ID and the submission time.

Example:

4
3 60 3
1 30
2 70
3 50
2 120 3
1 130
2 90
1 115
3 60 3
1 70
2 80
3 90
3 100 3
1 50
2 70
3 90

outputFormat

For each test case, output a single line containing the sorted list of team IDs that made at least one successful submission (i.e., submission time \(\le k\)). The team IDs should be separated by a single space. If no team qualifies, output an empty line.

Example Output:

1 3
1 2

1 2 3

## sample</p>
4
3 60 3
1 30
2 70
3 50
2 120 3
1 130
2 90
1 115
3 60 3
1 70
2 80
3 90
3 100 3
1 50
2 70
3 90
1 3

1 2

1 2 3

</p>