from collections import defaultdict

def solve():
    n, m = map(int, input().split())
    e = defaultdict(int)
    for _ in range(m):
        x = int(input())
        e[x] += 1
    answer = []
    for i in e:
        if e[i] >= n:
            answer.append(i)
    print(len(answer))
    print(*answer)

t = int(input())
for _ in range(t):
    solve()
