#C9839. Find Elements with Exact Frequency

    ID: 53976 Type: Default 1000ms 256MiB

Find Elements with Exact Frequency

Find Elements with Exact Frequency

You are given several test cases. In each test case, you have an array of integers and a target frequency (F). Your task is to identify the distinct elements in the array that appear exactly (F) times, preserving the order of their first occurrence. If no element meets the criteria, output (-1).

For example, if the array is [1, 2, 2, 3, 3] and (F = 2), the answer is "2 3" because 2 and 3 each appear exactly twice.

inputFormat

The input is read from standard input (stdin).

The first line contains an integer (T), the number of test cases. Each test case consists of two lines:
- The first line contains two integers (N) and (F), where (N) is the size of the array and (F) is the target frequency.
- The second line contains (N) space-separated integers representing the array elements.

outputFormat

For each test case, output a single line to standard output (stdout). The line should contain the distinct elements that appear exactly (F) times, in the order of their first occurrence, separated by spaces. If no element meets the criteria, output (-1).## sample

5
5 2
1 2 2 3 3
5 3
4 4 4 5 5
6 1
1 2 3 4 5 6
4 5
1 1 2 2
5 2
1 2 1 3 2
2 3

4 1 2 3 4 5 6 -1 1 2

</p>