I am not able to understand the output

I am not able to understand the output.

hi @riagoel3999,
Sample Input

1 <- no of testcases
5 2 <- no of elements and value of k
5 1 3 5 2 <- running stream data

first we got 5
so top 2 most freqent nos are 5 only as we have only one element so we print only one
ans= 5

then we got 1
so top 2 most frequent nos are 1 and 5 (in increasing order)
ans= 5 1 5

then we got 3
so top 2 most frequent nos are 1 3 (increasing order)
ans= 5 1 5 1 3

then we got 5
so top 2 most frequent nos are 5 and 1(smallest one )
ans=5 1 5 1 3 5 1

ans so on

i hope you got the point
reference code --> https://ide.codingblocks.com/s/640329