Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

You are an administrator of a popular quiz website. Every day, you hold a quiz on the website.

There are $N$ users (numbered $1$ through $N$) and $M$ admins (numbered $N+1$ through $N+M$). For each quiz, each user is allowed to attempt it at most once. Sometimes, admins attempt the quizzes for testing purposes too; an admin may attempt a quiz any number of times.

On a certain day, the quiz was attempted $K$ times. For each $i$ ($1 ≤ i ≤ K$), the $i$-th of these attempts was made by the person with number $L_{i}$. Find all the users who attempted the quiz more than once, in order to disqualify them.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains three space-separated integers $N$, $M$ and $K$.
The second line contains $K$ space-separated integers $L_{1}, L_{2}, \ldots, L_{K}$.

------  Output ------
For each test case, print a single line containing an integer $D$ denoting the number of users who should be disqualified, followed by a space and $D$ space-separated integers denoting their numbers in ascending order.

------  Constraints ------
$1 ≤ T ≤ 10$
$0 ≤ N, M ≤ 10^{5}$
$1 ≤ N + M, K ≤ 10^{5}$
$1 ≤ L_{i} ≤ N + M$ for each valid $i$

----- Sample Input 1 ------ 
3

1 1 1

1

1 1 2

1 1

5 5 10

2 5 2 5 2 4 10 10 10 10
----- Sample Output 1 ------ 
0

1 1

2 2 5
----- explanation 1 ------ 
Example case 1: Since there is only a single attempt during the whole day, there cannot be any user who made more than one attempt.

Example case 2: User $1$ attempted the quiz twice.

Example case 3: Users $2$ and $5$ attempted the quiz multiple times. The admin with number $10$ also attempted the quiz multiple times, but admins are allowed to do that.

Difficulty: MEDIUM
Tags: Data structures

Implementation
Skill types: Data structures

Starter code:

Solutions:
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	c = 0
	d = {}
	if n == 0:
		print(0)
	else:
		for i in range(k):
			if l1[i] in d:
				d[l1[i]] += 1
			elif l1[i] <= n + 1:
				d[l1[i]] = 1
		l2 = []
		for i in d.keys():
			if d[i] > 1:
				c += 1
				l2.append(i)
		print(c, end=' ')
		l = len(l2)
		l2.sort()
		for g in range(l):
			print(l2[g], end=' ')
		print()


for _ in range(int(input())):
	(n, m, k) = [int(i) for i in input().split()]
	l = [int(i) for i in input().split()]
	d = {}
	if n == 0:
		print(0)
	else:
		for i in range(k):
			if l[i] in d:
				d[l[i]] += 1
			elif l[i] <= n + 1:
				d[l[i]] = 1
		d = dict(sorted(d.items(), key=lambda x: x[1]))
		c = 0
		l1 = []
		for (key, val) in d.items():
			if val >= 2:
				l1.append(key)
				c += 1
		l1.sort()
		l1.insert(0, c)
		print(*l1, sep=' ')


import collections
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	d = collections.Counter(l)
	ans = []
	count = 0
	for i in d:
		if i > n:
			break
		elif d[i] > 1:
			count += 1
			ans.append(i)
	print(count, *ans)


t = int(input())
for i in range(t):
	(n, k, m) = map(int, input().split())
	lst = [int(x) for x in input().split()]
	lst2 = list()
	for i in range(n):
		lst2.append(1)
	lst3 = list()
	for i in range(m):
		a = lst[i]
		if a <= n:
			if lst2[a - 1] == 0:
				lst3.append(a)
			else:
				lst2[a - 1] -= 1
	s = set(lst3)
	print(len(s), *s, sep=' ')


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	cnt = [0] * (n + 1)
	res = []
	for i in l:
		if i <= n:
			cnt[i] += 1
			if cnt[i] == 2:
				res.append(i)
	print(len(res), *sorted(res))


for tc in range(int(input())):
	d = {}
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == 0:
		print(0)
	else:
		for i in range(k):
			if a[i] in d:
				d[a[i]] += 1
			elif a[i] <= n + 1:
				d[a[i]] = 1
		d = dict(sorted(d.items(), key=lambda x: x[1]))
		c = 0
		li = []
		for (key, val) in d.items():
			if val >= 2:
				li.append(key)
				c += 1
		li.sort()
		li.insert(0, c)
		print(*li, sep=' ')


for _ in range(int(input())):
	(N, M, K) = map(int, input().split())
	L = list(map(int, input().split()))
	disqualified_count = 0
	disqualified_users = []
	no_of_attempts = {}
	for i in L:
		if i < N + 1:
			if i in no_of_attempts:
				no_of_attempts[i] += 1
			else:
				no_of_attempts[i] = 1
	for i in range(1, N + 1):
		if i in no_of_attempts.keys() and no_of_attempts[i] > 1:
			disqualified_count += 1
			disqualified_users.append(i)
	print(disqualified_count, end=' ')
	for users in disqualified_users:
		print(users, end=' ')
	print()


from collections import Counter
t = int(input())
while t != 0:
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().strip().split()))[:k]
	x = Counter(l)
	b = []
	for i in x.keys():
		if x[i] > 1 and i <= n:
			b.append(i)
	b.sort()
	print(len(b), *b)
	t -= 1


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	d = {}
	b = []
	for i in a:
		try:
			d[i] += 1
		except:
			d[i] = 1
	for i in d.keys():
		if d[i] > 1 and i <= n:
			b.append(i)
	b.sort()
	print(len(b), *b)


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	list1 = list(map(int, input().split()))
	d1 = {}
	for i in list1:
		d1[i] = d1.get(i, 0) + 1
	k = []
	for (i, j) in d1.items():
		if j > 1 and i < n + 1:
			k.append(i)
		else:
			continue
	k.sort()
	print(len(k), *k)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	if n == m == k:
		print(0)
	l.sort()
	ans = [0] * (n + 1)
	cnt = 0
	for i in range(k):
		if l[i] > n:
			break
		ans[l[i]] += 1
		if ans[l[i]] == 2:
			cnt += 1
	res = [i for i in range(n + 1) if ans[i] > 1]
	print(cnt, *res)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	l = [0] * (n + 1)
	for i in a:
		if i <= n:
			l[i] += 1
	count = 0
	d = []
	for i in range(1, n + 1):
		if l[i] > 1:
			count += 1
			d.append(str(i))
	if count == 0:
		print(0)
	else:
		print(count, ' '.join(d))


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = [0] * (n + 1)
	if k == 1:
		print(0)
		continue
	res = list()
	mp = dict()
	for i in a:
		if i < n + 1:
			b[i] += 1
	cnt = 0
	for i in range(1, n + 1):
		if b[i] > 1:
			cnt += 1
	print(cnt, end=' ')
	for i in range(1, n + 1):
		if b[i] > 1:
			print(i, end=' ')
	print()


tests = int(input())
for i in range(tests):
	(n, m, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	users = [True for i in range(n)]
	submitted_users = set()
	for j in arr:
		if j <= n and j in submitted_users:
			users[j - 1] = False
		else:
			submitted_users.add(j)
	ans = []
	for j in range(n):
		if not users[j]:
			ans.append(j + 1)
	print(len(ans), *ans)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	tries = list(map(int, input().split()))
	a = list(range(1, n + 1))
	b = [0] * (n + m)
	for i in tries:
		b[i - 1] += 1
	c = []
	for i in range(n):
		if b[i] > 1:
			c.append(i + 1)
	print(len(c), *c)


def quiz(a, n, m, k):
	a.sort()
	r = []
	count = 1
	total = 0
	for i in range(k - 1):
		if a[i] > n:
			break
		if a[i] == a[i + 1]:
			count += 1
		elif count > 1:
			r.append(a[i])
			total += 1
			count = 1
	if count > 1:
		r.append(a[k - 1])
		total += 1
	if total != 0:
		print(total, *r)
	else:
		print(total)
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	quiz(a, n, m, k)


for _ in range(int(input())):
	(n, m, k) = [int(x) for x in input().split(' ')]
	arr = [int(x) for x in input().split(' ')]
	temp1 = {}
	temp2 = {}
	count = 0
	for i in arr:
		if i <= n and i not in temp1:
			temp1[i] = 1
		elif i <= n and i not in temp2:
			count += 1
			temp2[i] = 1
	temp = sorted(temp2)
	print(count, end=' ')
	for i in temp:
		print(i, end=' ')
	print()


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	r = []
	t = l[0]
	for i in range(1, k):
		if l[i] == t:
			if t <= n:
				r.append(t)
		else:
			t = l[i]
	print(len(set(r)), *set(r))


for i in range(int(input())):
	(N, M, K) = map(int, input().split())
	L = list(map(int, input().split()))
	L1 = dict()
	L2 = []
	count = 0
	for i in range(len(L)):
		if L[i] in L1.keys():
			L1[L[i]] += 1
		else:
			L1[L[i]] = 1
	for (key, value) in L1.items():
		if value > 1 and key <= N:
			L2.append(key)
			count += 1
	print(count, *sorted(L2))


from math import gcd, sqrt, ceil, floor, log
from heapq import heapify, heappop, heappush, nsmallest, nlargest
from collections import Counter, deque, OrderedDict, defaultdict
from itertools import combinations, permutations, zip_longest
from bisect import bisect_left, bisect_right
from functools import lru_cache, reduce
import sys
import time
import string
import operator
RECURSION_LIMIT = int(10000000.0)
INT_MAX = float('inf')
INT_MIN = float('-inf')
MOD = int(10000000.0) + 9
NEWLINE = '\n'
SPACE = ' '
sys.setrecursionlimit(RECURSION_LIMIT)
inp = lambda fn: fn(input())
inp_vars = lambda fn, delim, convert_to=list: convert_to(map(fn, input().split(delim)))
enum = lambda itr, start: enumerate(itr, start)

def toposort(graph, n):
	degree = [0] * n
	for node in graph:
		for adj in graph[node]:
			degree[adj] += 1
	bfs_queue = [node for node in range(n) if not degree[node]]
	for node in bfs_queue:
		for adj in graph[node]:
			degree[adj] -= 1
			if not degree[adj]:
				bfs_queue.append(adj)
	return (bfs_queue, degree)

def dfs(graph, node, visited):
	visited.add(node)
	for adj in graph[node]:
		if adj in visited:
			continue
		dfs(graph, adj, visited)

def seive(n):
	is_prime = [True] * (n + 1)
	is_prime[0] = is_prime[1] = False
	for i in range(2, int(n ** 0.5) + 1):
		if is_prime[i]:
			for j in range(i * i, n + 1, i):
				is_prime[j] = False
	return is_prime[n]

def bin_pow(x, y):
	if y == 0:
		return 1
	res = bin_pow(x, y >> 1)
	if y & 1 == 0:
		return res * res
	return x * res * res

def solve(*args, **kwargs):
	(n, m, k, arr) = args
	mp = Counter(arr)
	cheaters = sorted((key for (key, val) in mp.items() if val > 1 and 1 <= key <= n))
	res = [len(cheaters)]
	res.extend(cheaters)
	return res

def main(*args, **kwargs):
	for _ in range(int(input())):
		arg2 = inp_vars(int, SPACE)
		arg3 = inp_vars(int, SPACE)
		res = solve(*(*arg2, arg3))
		if type(res) in {list, tuple, set}:
			print(*res, sep=SPACE)
		else:
			print(res)
main()


from collections import Counter
testCases = int(input())
for testCase in range(testCases):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	if n != 0:
		ans = []
		for i in Counter(l).most_common():
			if i[1] > 1 and i[0] <= n:
				ans.append(i[0])
		print(len(ans), *sorted(ans))
	else:
		print(0)


tests = int(input())
for test in range(tests):
	(N, M, K) = [int(x) for x in input().split()]
	L = map(int, input().split())
	d = {}
	for i in L:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	people = []
	for (k, v) in d.items():
		if k <= N and v > 1:
			people.append(k)
	print(len(people), ' '.join(map(str, sorted(people))))


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = {}
	for id in l:
		if id >= 1 and id <= n:
			if id in d.keys():
				d[id] += 1
			else:
				d[id] = 1
	cnt = 0
	s = set()
	for k in d.keys():
		if d[k] > 1:
			cnt += 1
			s.add(k)
	print(cnt, end=' ')
	for item in s:
		print(item, end=' ')
	print()


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	L = list(map(int, input().split()))
	if k == 1:
		print(0)
		continue
	L.sort()
	li = [0] * (n + 1)
	count = 0
	for i in range(k):
		if L[i] > n:
			break
		li[L[i]] += 1
		if li[L[i]] == 2:
			count += 1
	mi = [i for i in range(n + 1) if li[i] > 1]
	print(count, *mi)


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	arr = list(map(int, input().lstrip().split()))
	di = dict()
	li = []
	for i in range(len(arr)):
		if arr[i] in di:
			di[arr[i]] += 1
		else:
			di[arr[i]] = 1
	for j in di:
		if n + 1 <= j <= n + m:
			continue
		elif di[j] > 1:
			li.append(j)
	if len(li) == 0:
		print(0)
	else:
		li.sort()
		li.insert(0, len(li))
		print(*li, sep=' ')


t = int(input())
while t > 0:
	(n, m, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	hashmap = {}
	ans = []
	for i in arr:
		if i <= n:
			if hashmap.get(i) != None:
				hashmap[i] += 1
				ans.append(i)
			else:
				hashmap[i] = 1
	ans = list(set(ans))
	z = len(ans)
	print(z, end=' ')
	for i in ans:
		print(i, end=' ')
	print('')
	t -= 1


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	list1 = list(map(int, input().split()))
	list2 = [0 for x in range(n + 1)]
	for j in list1:
		if j <= n:
			list2[j] += 1
	list4 = []
	l = 0
	s = len(list2)
	while l < s:
		if list2[l] > 1:
			list4.append(l)
		l += 1
	print(len(list4), end=' ')
	for z in list4:
		print(z, end=' ')
	print('')


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = [int(x) for x in input().split()]
	x = n + m + 1
	f = [0] * x
	ans = set()
	for i in l:
		if i <= n:
			f[i] += 1
	for i in l:
		if f[i] > 1 and i not in ans:
			ans.add(i)
	print(len(ans), *ans)


from collections import Counter
for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	q = []
	k = Counter(a)
	for i in k:
		if int(i) <= n and k[i] > 1:
			q.append(int(i))
	q.sort()
	print(len(q), *q)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	d = set()
	r = set()
	for j in l:
		if j <= n:
			if j in d:
				r.add(j)
			else:
				d.add(j)
	r = list(r)
	r.sort()
	print(len(r), *r)


from collections import Counter

def main():
	for _ in range(int(input())):
		(n, m, k) = map(int, input().split(' '))
		a = list(map(int, input().split(' ')))
		a.sort()
		a1 = Counter(a)
		a2 = []
		for i in a1.keys():
			if a1[i] > 1 and i <= n:
				a2.append(i)
		if len(a2) > 0:
			print(len(a2), *a2)
		else:
			print(0)
main()


n = int(input())
for x in range(n):
	q = input()
	m = int(q.split(' ')[0])
	n = int(q.split(' ')[1])
	r = int(q.split(' ')[2])
	dict1 = {}
	y = input()
	for x in y.split(' '):
		if x in dict1:
			dict1[x] = dict1[x] + 1
		else:
			dict1[x] = 1
	dict2 = {}
	for x in range(1, m + 1):
		m = str(x)
		if m in dict1 and dict1[m] > 1:
			dict2[x] = dict1[m]
	m = str(len(dict2)) + ' '
	for x in sorted(dict2):
		n = str(x)
		m = m + n + ' '
	print(m[:-1])


for _ in range(int(input())):
	(N, M, K) = map(int, input().split())
	L = list(map(int, input().split()))
	freq = {}
	for i in L:
		if i >= 1 and i <= N:
			if i in freq.keys():
				freq[i] += 1
			else:
				freq[i] = 1
	count = 0
	s = set()
	for j in freq.keys():
		if freq[j] > 1:
			count += 1
			s.add(j)
	print(count, end=' ')
	for item in s:
		print(item, end=' ')
	print()


from collections import Counter
import math
import sys
for j in range(int(input())):
	(n, m, k) = map(int, input().split())
	kl = list(map(int, input().split()))
	l = Counter(kl)
	p = []
	for i in l:
		if int(i) <= n and l[i] > 1:
			p.append(int(i))
	p = sorted(p)
	print(len(p), *p)


n = int(input())
for i in range(n):
	(N, M, K) = [int(x) for x in input().split(' ')]
	arr = [int(x) for x in input().split(' ')]
	dict = {}
	cnt = 0
	ansarr = []
	for i in arr:
		if i not in dict:
			dict[i] = 1
		else:
			dict[i] += 1
	for keys in dict:
		if dict[keys] > 1 and keys <= N:
			cnt += 1
			ansarr.append(keys)
	ansarr.sort()
	print(len(ansarr), end=' ')
	for i in ansarr:
		print(i, end=' ')
	print()


T = int(input())
for _ in range(T):
	(n, m, k) = map(int, input().split())
	L = list(map(int, input().split()))
	d = {}
	for i in range(1, n + 1):
		d[i] = 0
	for i in range(k):
		a = L[i]
		if a <= n:
			d[a] += 1
	M = []
	ans = 0
	for i in range(1, n + 1):
		if d[i] > 1:
			ans += 1
			M.append(i)
	M.insert(0, ans)
	print(*M)


from collections import defaultdict
for _ in range(int(input())):
	(n, m, k) = (int(i) for i in input().split())
	a = [int(x) for x in input().split()]
	cnt = defaultdict(int)
	for i in a:
		if i <= n:
			cnt[i] += 1
	ans = []
	total = 0
	for i in cnt:
		if cnt[i] > 1:
			ans.append(i)
			total += 1
	print(total, *sorted(ans))


import sys
input = sys.stdin.readline

def rii():
	return range(int(input().strip()))

def ii():
	return int(input().strip())

def mii():
	return map(int, input().strip().split(' '))

def lmii():
	return list(map(int, input().strip().split(' ')))

def si():
	return str(input().strip())
from collections import defaultdict
from functools import reduce

def solve(*args):
	(n, m, k, l) = args
	attempts = defaultdict(int)
	admins = range(n + 1, n + m + 1)
	for x in l:
		if x in admins:
			continue
		attempts[x] += 1
	ans = [x for x in attempts if attempts[x] > 1]
	l_ans = len(ans)
	if len(ans) == 0:
		return f'{l_ans}'
	else:
		ans = reduce(lambda x, y: str(x) + ' ' + str(y), sorted(ans))
		return f'{l_ans} {ans}'

def do_codechef():
	for t in rii():
		(n, m, k) = mii()
		l = lmii()
		print(solve(n, m, k, l))
do_codechef()
exit()


from collections import Counter
T = int(input())
for tj in range(T):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	l1 = Counter(l)
	l2 = []
	for i in l1.keys():
		if l1[i] > 1 and i <= n:
			l2.append(i)
	if len(l2) > 0:
		print(len(l2), *l2)
	else:
		print(0)


try:
	for i in range(int(input())):
		(n, m, k) = map(int, input().split(' '))
		l = list(map(int, input().split(' ')))
		m = {}
		for i in range(k):
			if l[i] not in m:
				m[l[i]] = 0
			m[l[i]] += 1
		count = 0
		p = []
		for i in range(1, n + 1):
			if i in m and m[i] > 1:
				count += 1
				p.append(i)
		p.sort()
		print(count, end=' ')
		for i in p:
			print(i, end=' ')
		print()
except Exception:
	pass


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	dic = {}
	for i in l:
		if i <= n:
			if i in dic:
				dic[i] += 1
			else:
				dic[i] = 1
	l = list(dic.keys())
	for i in l:
		if dic[i] == 1:
			del dic[i]
	if dic == {}:
		print(0)
		continue
	l = list(dic.keys())
	l.sort()
	l.insert(0, len(l))
	o = ''
	for i in l:
		o += str(i) + ' '
	o = o[:len(o) - 1]
	print(o)


t = int(input())
for z in range(t):
	(n, m, k) = map(int, input().split())
	a = list(map(int, input().split()))
	r = []
	l = [0 for i in range(0, n + 1)]
	for i in a:
		if i <= n:
			l[i] += 1
	for i in range(len(l)):
		if l[i] > 1:
			r.append(i)
	print(len(r), *r)


t = int(input())
while t != 0:
	(n, m, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	s = {}
	res = set()
	for i in ar:
		if m >= 1 and i >= n + 1:
			continue
		elif i in s:
			s[i] = s[i] + 1
		else:
			s[i] = 1
	for i in s:
		if s[i] > 1:
			res.add(i)
	res = sorted(res)
	print(len(res), ' '.join((str(i) for i in res)))
	t -= 1


from collections import Counter
for gagroz in range(int(input())):
	(N, M, K) = map(int, input().split())
	L = list(map(int, input().split()))
	res = []
	temp = Counter(L)
	for key in temp:
		if key <= N and temp[key] > 1:
			res.append(key)
	res = sorted(res)
	print(len(res), end=' ')
	print(*res)


t = int(input())
for tc in range(t):
	(n, m, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	d = set()
	res = set()
	for num in arr:
		if num <= n:
			if num in d:
				res.add(num)
			else:
				d.add(num)
	res = list(res)
	res.sort()
	print(len(res), *res)


for z in range(int(input())):
	(n, m, k) = map(int, input().strip().split())
	arr = list(map(int, input().strip().split()))
	arr = sorted(arr)
	s = set()
	c = 0
	s2 = set()
	ans = ''
	for i in arr:
		if i <= n:
			if i not in s:
				s.add(i)
			else:
				if i not in s2:
					ans = ans + str(i) + ' '
					c += 1
				s2.add(i)
	if c == 0:
		print('0')
	else:
		print(str(c) + ' ' + ans)


from collections import Counter
t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l3 = []
	if k == 1:
		print(0)
	else:
		l1 = Counter(l)
		for ele in l1:
			if ele in range(1, n + 1):
				if l1[ele] > 1:
					l3.append(ele)
		l3.sort()
		print(len(l3), end=' ')
		for elee in l3:
			print(elee, end=' ')
		print()


t = int(input())
for i in range(t):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	c = 0
	a = []
	for j in range(k - 2):
		if l[j] == l[j + 1] and l[j + 1] != l[j + 2] and (l[j] <= n):
			c = c + 1
			a.append(l[j])
	if l[k - 1] == l[k - 2] and l[k - 1] <= n:
		c = c + 1
		a.append(l[k - 1])
	if k != 1:
		print(c, *a, sep=' ')
	else:
		print(0)


for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	c = [0] * (n + m + 1)
	for j in range(k):
		c[l[j]] += 1
	d = []
	for j in range(1, n + 1):
		if c[j] > 1:
			d.append(j)
	print(len(d), end=' ')
	for j in range(len(d)):
		print(d[j], end=' ')
	print()


from collections import Counter
for i in range(int(input())):
	(n, m, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	darr = Counter(arr)
	arr1 = []
	for i in darr:
		if i in range(1, n + 1):
			if darr[i] > 1:
				arr1.append(i)
	arr1.sort()
	print(len(arr1), end=' ')
	print(*arr1)


for u in range(int(input())):
	(n, m, k) = map(int, input().split())
	x = [int(w) for w in input().split()]
	candi = {i: 0 for i in range(1, n + 1)}
	for i in x:
		if 1 <= i <= n:
			candi[i] += 1
	ans = []
	for i in candi:
		if candi[i] > 1:
			ans.append(i)
	if len(ans):
		ans = [len(ans)] + ans
		print(*ans)
	else:
		print(0)


from collections import Counter
T = int(input())
for tx in range(T):
	(N, M, K) = map(int, input().split())
	L_ct = Counter((u for u in map(int, input().split()) if u <= N))
	DQ = sorted((k for (k, v) in L_ct.items() if v > 1))
	print(len(DQ), ' '.join(map(str, DQ)))


import collections
t = int(input())
for i in range(t):
	(n, m, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	d = collections.Counter(a)
	a = []
	for i in d:
		if d[i] > 1 and i <= n:
			a.append(i)
	a = sorted(a)
	print(len(a), end=' ')
	for i in a:
		print(i, end=' ')
	print()


from collections import Counter as cnt
tc = int(input())
for tci in range(tc):
	d = []
	inp = input().split(' ')
	n = int(inp[0])
	m = int(inp[1])
	k = int(inp[2])
	inp = input().split(' ')
	count = cnt(inp)
	for i in range(1, n + 1):
		if count[str(i)] > 1:
			d.append(str(i))
	print(len(d), end=' ')
	print(' '.join(d))


from collections import Counter
for i in range(int(input())):
	(n, m, k) = [int(x) for x in input().split()]
	nums = [int(x) for x in input().split()]
	disqual = Counter(nums)
	count = []
	for (a, b) in disqual.items():
		if b > 1 and a <= n:
			count.append(a)
	count.sort()
	print(len(count), end=' ')
	for j in range(len(count)):
		print(count[j], end=' ')
	print()


try:
	test = int(input())
	for i in range(test):
		disqual = []
		(n, m, k) = map(int, input().split())
		karr = list(map(int, input().split()))
		d = {}
		for x in karr:
			if x in d.keys():
				d[x] = d[x] + 1
			else:
				d[x] = 1
		for x in d:
			if d[x] > 1:
				if x <= n:
					disqual.append(x)
		disqual.sort()
		disqual.insert(0, len(disqual))
		print(*disqual, sep=' ')
except:
	pass


a = int(input())
for i in range(a):
	(n, m, k) = map(int, input().split())
	c = list(map(int, input().split()))
	p = 0
	t = 0
	f = 0
	e = []
	f = {}
	for i in c:
		if i in range(1, n + 1):
			if i in f:
				f[i] = f[i] + 1
			else:
				f[i] = 1
	for i in f:
		if f[i] > 1:
			e.append(i)
	e.sort()
	print(len(e), *e)


t = int(input())
for _ in range(t):
	(n, m, k) = map(int, input().split())
	li = list(map(int, input().split()))
	dic = {}
	for i in range(k):
		if li[i] in dic:
			dic[li[i]] += 1
		else:
			dic[li[i]] = 1
	opli = []
	for i in dic:
		if dic[i] > 1 and i <= n:
			opli.append(i)
	opli.sort()
	print(len(opli), end=' ')
	for i in opli:
		print(i, end=' ')
	print()


t = int(input())
for i in range(t):
	(a, b, c) = map(int, input().split())
	ans = []
	helper = {}
	arr = list(map(int, input().split()))
	for i in arr:
		if i <= a:
			if i in helper:
				helper[i] += 1
			else:
				helper[i] = 1
	for i in helper:
		if helper[i] > 1:
			ans.append(i)
	ans.sort()
	print(len(ans), *ans)


t = int(input())
for _ in range(t):
	(N, M, K) = map(int, input().split())
	L = list(map(int, input().split()))
	freq = dict()
	answers = set()
	for item in L:
		freq[item] = freq.get(item, 0) + 1
		if item <= N and freq[item] > 1:
			answers.add(item)
	print(f"{len(answers)} {' '.join(map(str, sorted(list(answers))))}")


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	l = list(map(int, input().split()))
	s = [0] * (n + 1)
	for i in l:
		if i > n:
			continue
		else:
			s[i] += 1
	all = []
	for i in range(1, n + 1):
		if s[i] > 1:
			all.append(str(i))
	print(len(all), end=' ')
	print(' '.join(all))


def merge_sort(data, left, right):
	if right - left < 1:
		return data[left:right + 1]
	else:
		mid = (left + right) // 2
		left = merge_sort(data, left, mid)
		right = merge_sort(data, mid + 1, right)
		return merge(left, right)

def merge(left, right):
	len_left = len(left)
	len_right = len(right)
	total_len = len_left + len_right
	new_data = []
	i = j = 0
	for index in range(total_len):
		if i == len_left:
			new_data.append(right[j])
			j += 1
		elif j == len_right:
			new_data.append(left[i])
			i += 1
		elif left[i] <= right[j]:
			new_data.append(left[i])
			i += 1
		elif left[i] > right[j]:
			new_data.append(right[j])
			j += 1
	return new_data
result = []
try:
	for testcase in range(int(input())):
		(n, m, k) = tuple(map(int, input().split()))
		data = list(map(int, input().split()))
		data.sort()
		count = {}
		answer = []
		for value in data:
			if value <= n:
				count[value] = count.get(value, 0) + 1
		for (key, value) in count.items():
			if value > 1:
				answer.append(key)
		answer.insert(0, len(answer))
		result.append(answer)
	for testcase in result:
		for (index, value) in enumerate(testcase):
			if index == len(testcase) - 1:
				print(value)
			else:
				print(value, end=' ')
except:
	pass