You're given an array of $n$ integers between $0$ and $n$ inclusive.

In one operation, you can choose any element of the array and replace it by the MEX of the elements of the array (which may change after the operation).

For example, if the current array is $[0, 2, 2, 1, 4]$, you can choose the second element and replace it by the MEX of the present elements  — $3$. Array will become $[0, 3, 2, 1, 4]$.

You must make the array non-decreasing, using at most $2n$ operations.

It can be proven that it is always possible. Please note that you do not have to minimize the number of operations. If there are many solutions, you can print any of them.

 –

An array $b[1 \ldots n]$ is non-decreasing if and only if $b_1 \le b_2 \le \ldots \le b_n$.

The MEX (minimum excluded) of an array is the smallest non-negative integer that does not belong to the array. For instance:  The MEX of $[2, 2, 1]$ is $0$, because $0$ does not belong to the array.  The MEX of $[3, 1, 0, 1]$ is $2$, because $0$ and $1$ belong to the array, but $2$ does not.  The MEX of $[0, 3, 1, 2]$ is $4$ because $0$, $1$, $2$ and $3$ belong to the array, but $4$ does not. 

It's worth mentioning that the MEX of an array of length $n$ is always between $0$ and $n$ inclusive.


-----Input-----

The first line contains a single integer $t$ ($1 \le t \le 200$) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer $n$ ($3 \le n \le 1000$) — length of the array.

The second line of each test case contains $n$ integers $a_1, \ldots, a_n$ ($0 \le a_i \le n$) — elements of the array. Note that they don't have to be distinct.

It is guaranteed that the sum of $n$ over all test cases doesn't exceed $1000$.


-----Output-----

For each test case, you must output two lines:

The first line must contain a single integer $k$ ($0 \le k \le 2n$)  — the number of operations you perform.

The second line must contain $k$ integers $x_1, \ldots, x_k$ ($1 \le x_i \le n$), where $x_i$ is the index chosen for the $i$-th operation.

If there are many solutions, you can find any of them. Please remember that it is not required to minimize $k$.


-----Example-----
Input
5
3
2 2 3
3
2 1 0
7
0 7 3 1 3 7 7
9
2 0 1 1 2 4 4 2 0
9
8 4 7 6 1 2 3 0 5

Output
0

2
3 1
4
2 5 5 4
11
3 8 9 7 8 5 9 6 4 1 2
10
1 8 1 9 5 2 4 6 3 7



-----Note-----

In the first test case, the array is already non-decreasing ($2 \le 2 \le 3$).

Explanation of the second test case (the element modified by each operation is colored in red):   $a = [2, 1, 0]$ ; the initial MEX is $3$.  $a = [2, 1, \color{red}{3}]$ ; the new MEX is $0$.  $a = [\color{red}{0}, 1, 3]$ ; the new MEX is $2$.  The final array is non-decreasing: $0 \le 1 \le 3$. 

Explanation of the third test case:   $a = [0, 7, 3, 1, 3, 7, 7]$ ; the initial MEX is $2$.  $a = [0, \color{red}{2}, 3, 1, 3, 7, 7]$ ; the new MEX is $4$.  $a = [0, 2, 3, 1, \color{red}{4}, 7, 7]$ ; the new MEX is $5$.  $a = [0, 2, 3, 1, \color{red}{5}, 7, 7]$ ; the new MEX is $4$.  $a = [0, 2, 3, \color{red}{4}, 5, 7, 7]$ ; the new MEX is $1$.  The final array is non-decreasing: $0 \le 2 \le 3 \le 4 \le 5 \le 7 \le 7$.

Difficulty: MEDIUM

Starter code:

Solutions:
import sys
input = sys.stdin.buffer.readline

def print(val):
	sys.stdout.write(val + '\n')

def mex(nums, n):
	taken = [False] * (n + 1)
	for i in range(n):
		taken[nums[i]] = True
	for i in range(n + 1):
		if taken[i] == False:
			break
	return i

def prog():
	for _ in range(int(input())):
		n = int(input())
		nums = list(map(int, input().split()))
		output = []
		bad = set()
		for i in range(n):
			if nums[i] != i:
				bad.add(i)
		for j in range(len(bad)):
			curr = mex(nums, n)
			if curr == n:
				for i in bad:
					nums[i] = n
					output.append(i + 1)
					break
				curr = mex(nums, n)
			nums[curr] = curr
			bad.remove(curr)
			output.append(curr + 1)
		print(str(len(output)))
		print(' '.join(map(str, output)))
prog()


for _ in ' ' * int(input()):
	p = input
	a = int(p())
	b = []
	z = [*range(a)]
	z1 = [*range(0, a + 1)]
	c = list(map(int, p().split()))
	while len(sorted(set(z).difference(set(c)))) != 0:
		r = sorted(set(z).difference(set(c)))[0]
		c[r] = r
		b += [r + 1]
	for i in range(a):
		if c[i] != i:
			r = sorted(set(z1).difference(set(c)))[0]
			while i in c:
				b += [c.index(i) + 1]
				c[c.index(i)] = r
			c[i] = i
			b += [i + 1]
	print(len(b))
	print(*b)


def mex(arr):
	n = len(arr)
	ans = n
	l = [0] * (n + 1)
	for i in arr:
		l[i] += 1
	for i in range(n + 1):
		if l[i] == 0:
			ans = i
			break
	return ans
for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	k = 0
	ans = []
	while True:
		if arr == sorted(arr):
			break
		a = mex(arr)
		if a == n:
			for i in range(n):
				if arr[i] != i:
					arr[i] = n
					k += 1
					ans.append(i + 1)
					break
		elif arr[a] != a:
			arr[a] = a
			k += 1
			ans.append(a + 1)
	print(k)
	print(*ans)


def findmex(x):
	arr = [0] * (n + 1)
	for i in x:
		arr[i] += 1
	for i in range(n + 1):
		if arr[i] == 0:
			return i
	return n
t = int(input())
for _ in range(t):
	n = int(input())
	x = list(map(int, input().split()))
	mex_arr = []
	while 1:
		if x == sorted(x):
			break
		mex = findmex(x)
		if mex < n:
			if x[mex] != mex:
				x[mex] = mex
				mex_arr.append(mex + 1)
		else:
			for i in range(n):
				if x[i] != i:
					x[i] = n
					mex_arr.append(i + 1)
					break
	print(len(mex_arr))
	print(*mex_arr)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))

def desc(arr, m):
	for i in range(m - 1):
		if arr[i] > arr[i + 1]:
			return 1
	return 0

def findMex(arr, m):
	arr = [-1] + sorted(arr)
	for i in range(1, len(arr)):
		if arr[i - 1] != arr[i] and arr[i - 1] + 1 != arr[i]:
			return arr[i - 1] + 1
	return max(arr) + 1
(n,) = I()
while n:
	(m,) = I()
	arr = I()
	change = []
	while desc(arr, m):
		mex = findMex(arr, m)
		if mex == m:
			for i in range(m):
				if arr[i] != i:
					arr[i] = mex
					change.append(i + 1)
					break
		else:
			arr[mex] = mex
			change.append(mex + 1)
	print(len(change))
	print(*change)
	n -= 1


import time
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	counts = [0 for _ in range(n + 1)]
	for i in range(n):
		counts[a[i]] += 1
	k = 0
	idx = []
	while True:
		i = 0
		while counts[i] != 0:
			i += 1
		done = True
		if i == n:
			for j in range(n):
				if a[j] != j:
					k += 1
					counts[a[j]] -= 1
					a[j] = i
					counts[i] += 1
					done = False
					idx.append(j + 1)
					break
		else:
			k += 1
			counts[a[i]] -= 1
			a[i] = i
			counts[i] += 1
			done = False
			idx.append(i + 1)
		if done:
			break
	print(k)
	print(' '.join(map(str, idx)))


def find(arr):
	copy = list(set(arr[:]))
	copy.sort()
	for i in range(len(copy)):
		if copy[i] != i:
			return i
	return len(copy)

def increasing(arr):
	for i in range(1, len(arr)):
		if arr[i] < arr[i - 1]:
			return False
	return True

def solve(arr, n, ans):
	moves = []
	while True:
		if increasing(arr):
			break
		mex = find(arr)
		if mex < len(arr):
			index = mex
		else:
			for i in range(len(arr)):
				if arr[i] != i:
					index = i
					break
		arr[index] = mex
		moves.append(index + 1)
	ans.append(moves)

def main():
	t = int(input())
	ans = []
	for i in range(t):
		n = int(input())
		arr = list(map(int, input().split()))
		solve(arr, n, ans)
	for i in ans:
		print(len(i))
		for j in i:
			print(j, end=' ')
		print()
main()


import sys
from collections import Counter

def rl():
	return sys.stdin.readline().strip()

def MEX(a):
	c = Counter(a)
	for i in range(n + 1):
		if c[i] == 0:
			return i
T = int(rl())
for test in range(T):
	n = int(rl())
	a = [int(x) for x in rl().split()]
	c = Counter(a)
	goal = [i for i in range(n)]
	mex = MEX(a)
	count = 0
	ans = []
	unvisited = [i for i in range(n)]
	while a != goal:
		count += 1
		if mex == n:
			temp = unvisited[0]
			index = a.index(unvisited[0])
			a[index] = mex
			ans.append(index + 1)
			mex = temp
		else:
			a[mex] = mex
			unvisited.remove(mex)
			ans.append(mex + 1)
			mex = MEX(a)
	print(count)
	print(' '.join([str(x) for x in ans]))


def mex(a):
	n = len(a)
	s = [0] * (n + 1)
	for i in range(n):
		s[a[i]] += 1
	for i in range(n + 1):
		if s[i] == 0:
			return i
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	count = []
	while 1:
		p = mex(a)
		if p != n:
			a[p] = p
			count.append(p + 1)
		else:
			sp = 1
			for i in range(n):
				if a[i] != i:
					a[i] = p
					count.append(i + 1)
					sp = 0
					break
			if sp:
				break
	print(len(count))
	print(*count, sep=' ')


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
for _ in range(int(data())):
	n = int(data())
	arr = l()
	answer = []
	not_in_place = 0
	while True:
		r = True
		for i in range(1, n):
			if arr[i] < arr[i - 1]:
				r = False
				break
		if r:
			break
		c = C(arr)
		mex = 0
		for i in range(n + 1):
			if not c[i]:
				mex = i
				break
		if mex < n:
			arr[mex] = mex
			answer.append(mex + 1)
			continue
		for i in range(n):
			if arr[i] != i:
				arr[i] = mex
				answer.append(i + 1)
				break
	out(len(answer))
	out(*answer)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	res = []
	for i in range(n * 2):
		s = set(a)
		for j in range(n + 1):
			if j not in s:
				mex = j
				break
		if mex == n:
			for j in range(n - 1):
				if a[j] > a[j + 1]:
					a[j] = mex
					res.append(j + 1)
					break
		else:
			a[mex] = mex
			res.append(mex + 1)
	print(len(res))
	print(*res)


def findMex(c):
	mex = 0
	while c[mex]:
		mex += 1
	return mex

def solve(n, a):
	c = [0 for i in range(n + 1)]
	for i in a:
		c[i] += 1
	b = []
	for i in range(n):
		mex = findMex(c)
		if mex == n:
			j = 0
			while j < n and j == a[j]:
				j += 1
			if j <= n - 1:
				c[mex] += 1
				ind = a.index(j)
				c[j] -= 1
				a[ind] = mex
				b.append(ind + 1)
				mex = j
			else:
				return b
		c[a[mex]] -= 1
		c[mex] += 1
		a[mex] = mex
		b.append(mex + 1)
	return b
t = int(input())
for turn in range(t):
	n = int(input())
	m = input()
	a = [int(x) for x in m.split()]
	b = solve(n, a)
	print(len(b))
	print(*b)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def mex(ar):
	i = 0
	while ar[i]:
		i += 1
	return i
for o in range(int(input())):
	n = int(input())
	ile = [0] * (n + 1)
	a = list(map(int, input().split()))
	for i in a:
		ile[i] += 1
	aa = []
	for i in range(2 * n):
		m = mex(ile)
		if m == n:
			for j in range(n):
				if j != a[j]:
					ile[a[j]] -= 1
					ile[m] += 1
					a[j] = m
					aa.append(j + 1)
					break
			else:
				break
		else:
			ile[a[m]] -= 1
			ile[m] += 1
			a[m] = m
			aa.append(m + 1)
	print(len(aa))
	print(*aa)


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n
avl = AvlTree()

class SegmentTree1:

	def __init__(self, data, default='z', func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

def calc(l):
	i = 0
	s = set(l)
	while i in s:
		i += 1
	return i
for ik in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = []
	t = 0
	ind = 0
	while True:
		mex = calc(l)
		if l == sorted(l):
			break
		if mex == n:
			while l[ind] == ind:
				ind += 1
			l[ind] = n
			ans.append(ind + 1)
			ind += 1
		else:
			ans.append(mex + 1)
			l[mex] = mex
			t += 1
			if t == n:
				break
	print(len(ans))
	print(*ans, sep=' ')


def GetMEH(nums):
	nums_set = set(nums)
	for i in range(1002):
		if i not in nums_set:
			return i

def Check(nums):
	for i in range(1, len(nums)):
		if nums[i] < nums[i - 1]:
			return False
	return True
t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	nums = list(map(int, input().split(' ')))
	ans.append([])
	while not Check(nums):
		while GetMEH(nums) < n and (not Check(nums)):
			curr_meh = GetMEH(nums)
			nums[curr_meh] = curr_meh
			ans[-1].append(curr_meh)
		for i in range(n):
			if nums[i] != i:
				nums[i] = GetMEH(nums)
				ans[-1].append(i)
				break
for i in ans:
	print(len(i))
	for j in i:
		print(j + 1, end=' ')
	print()


from sys import stdin, stdout
input = stdin.readline
from collections import Counter, defaultdict
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = defaultdict(int, Counter(a))
	ans = []
	for idx in range(2 * n):
		mini = n + 1
		for i in range(n + 1):
			if c[i] == 0:
				mini = min(i, mini)
		if mini != n:
			c[a[mini]] -= 1
			a[mini] = mini
			c[mini] += 1
			ans.append(mini + 1)
		else:
			for i in range(n):
				if a[i] != i:
					c[a[i]] -= 1
					a[i] = mini
					c[mini] += 1
					ans.append(i + 1)
					break
			else:
				break
	print(len(ans))
	print(*ans)


import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for t in range(T):
	(N,) = map(int, input().split())
	X = list(map(int, input().split()))
	R = []
	while True:
		d = set(range(N + 1))
		for i in range(N):
			if X[i] in d:
				d.remove(X[i])
		dx = min(d)
		if dx == N:
			break
		R.append(dx + 1)
		X[dx] = dx
	ss = []
	for i in range(N):
		if X[i] != i:
			ss.append(i)
	ss = ss[::-1]
	m = N
	while ss:
		if X[ss[-1]] == ss[-1]:
			ss.pop()
			continue
		if m == N:
			si = ss.pop()
			for i in range(N):
				if X[i] == si:
					X[i] = m
					R.append(i + 1)
					m = X[si]
					X[si] = si
					R.append(si + 1)
					break
		else:
			R.append(m + 1)
			(X[m], m) = (m, X[m])
	print(len(R))
	print(*R)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A):
	ops = []
	seen = Counter(A)
	mex = 0
	while seen[mex]:
		mex += 1
	for j in range(N - 1, -1, -1):
		if A[j] != j:
			i = j
			while True:
				replaced = A[i]
				seen[replaced] -= 1
				ops.append(i)
				A[i] = mex
				seen[mex] += 1
				if seen[replaced] == 0 and replaced < mex:
					mex = replaced
				while seen[mex]:
					mex += 1
				i = mex
				if A[j] == j or mex == N:
					break
	assert A == sorted(A)
	assert len(ops) <= 2 * N
	return str(len(ops)) + '\n' + ' '.join((str(i + 1) for i in ops))
if False:
	import random
	random.seed(0)
	for j in range(100):
		N = 20
		A = [random.randint(0, 3 * N) for i in range(N)]
		print(A)
		solve(N, A)
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


import sys
input = sys.stdin.readline

def findmex(arr):
	freq = [0] * (max(a) + 5)
	for i in range(n):
		freq[arr[i]] += 1
	for i in range(len(freq)):
		if freq[i] == 0:
			return i
t = int(input())
for ii in range(t):
	n = int(input())
	a = [int(i) for i in input().split() if i != '\n']
	mex = findmex(a)
	ans = []
	while True:
		if mex <= n - 1:
			a[mex] = mex
			ans.append(mex + 1)
			mex = findmex(a)
		else:
			for i in range(n):
				if a[i] != i:
					a[i] = mex
					ans.append(i + 1)
					mex = findmex(a)
					break
			else:
				break
	print(len(ans))
	print(*ans)


from collections import Counter
t = int(input())

def is_ok(a):
	for i in range(len(a) - 1):
		if a[i + 1] < a[i]:
			return False
	return True
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	m = Counter(a)
	mex = min(set(range(n + 1)) - set(m))
	r = []
	for _ in range(2 * n):
		ind = mex
		if mex == n:
			for i in range(n):
				if a[i] != i:
					ind = i
					break
			if ind >= n:
				break
		m[a[ind]] -= 1
		m[mex] += 1
		new_mex = min(a[ind], mex + 1)
		while m[new_mex] > 0:
			new_mex += 1
		old_mex = mex
		a[ind] = mex
		r.append(ind + 1)
		mex = new_mex
	print(len(r))
	print(*r)


def sort(a):
	c = 0
	for z in range(1, len(a)):
		if a[z] < a[z - 1]:
			c = 0
			break
		else:
			c = 1
	if c == 0:
		return False
	return True
t = int(input())
for i in range(t):
	n = int(input())
	a = list((int(num) for num in input().split()))
	if sort(a):
		print('0')
		print(' ')
	else:
		p = [-1] * (n + 1)
		f = [0] * (n + 1)
		for z in range(len(a)):
			if p[a[z]] == -1:
				p[a[z]] = 0
			f[a[z]] += 1
		cl = []
		c = 0
		while c == 0:
			idx = p.index(-1)
			if idx == n:
				for z in range(0, len(a)):
					if a[z] != z:
						break
				cl.append(z + 1)
				f[a[z]] -= 1
				if f[a[z]] == 0:
					p[a[z]] = -1
				a[z] = idx
				f[a[z]] += 1
				p[idx] = 0
			else:
				cl.append(idx + 1)
				f[a[idx]] -= 1
				if f[a[idx]] == 0:
					p[a[idx]] = -1
				a[idx] = idx
				f[a[idx]] += 1
				p[idx] = 0
			if sort(a):
				c = 1
		print(len(cl))
		print(*cl)


t = int(input())

def issorted(a):
	for i in range(1, len(a)):
		if a[i] < a[i - 1]:
			return False
	return True

def mex(a):
	seta = set(a)
	for i in range(len(a) + 1):
		if not i in seta:
			return i

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	res = []
	while not issorted(a):
		k = mex(a)
		if k == n:
			t = 0
			while a[t] == t:
				t += 1
			a[t] = k
			res.append(t + 1)
		else:
			a[k] = k
			res.append(k + 1)
	print(len(res))
	print(' '.join(map(str, res)))
for _ in range(t):
	solve()


test = int(input())
for t in range(test):
	si = int(input())
	a = list(map(int, input().split()))
	f = [i == n for (n, i) in enumerate(a)]
	r = []
	stop = 0
	while False in f:
		sa = sorted(a)
		m = -1
		for i in sa:
			if i == m or i == m + 1:
				m = i
			else:
				break
		m += 1
		if m == si:
			for (n, i) in enumerate(f):
				if not i:
					a[n] = si
					break
			r.append(n + 1)
		else:
			a[m] = m
			f[m] = True
			r.append(m + 1)
	print(len(r))
	print(' '.join(map(str, r)))


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heapreplace, heappushpop

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline().rstrip()

def lsi():
	return list(si())
res = ['YES', 'NO']
test_case = ii()
while test_case:
	test_case -= 1
	n = ii()
	a = li()
	cnt = [0] * (n + 1)
	for i in a:
		cnt[i] += 1
	h = []
	for i in range(n + 1):
		if not cnt[i]:
			h.append(i)
	heapify(h)
	ans = []
	for _ in range(n + n):
		z = heappop(h)
		cnt[z] += 1
		ps = z
		if ps == n:
			for i in range(n):
				if a[i] != i:
					ps = i
					break
		if ps == n:
			break
		cnt[a[ps]] -= 1
		if not cnt[a[ps]]:
			heappush(h, a[ps])
		a[ps] = z
		ans.append(ps + 1)
		if not h:
			break
	print(len(ans))
	print(*ans)


import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *
from heapq import *
from math import *
from itertools import permutations

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')

def li():
	return [int(x) for x in input().split()]

def fli():
	return [float(x) for x in input().split()]

def gi():
	return [x for x in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)

def bo(i):
	return ord(i) - ord('a')
tt = fi()
while tt > 0:
	tt -= 1
	n = fi()
	a = li()
	mex = 0
	d = [0 for i in range(n + 2)]
	for i in range(n):
		if a[i] <= n:
			d[a[i]] += 1
		if a[i] == mex:
			while d[mex] > 0:
				mex += 1
	j = n
	tle = 0
	l = 0
	ans = []
	for i in range(n):
		if a[i] == i:
			j -= 1
	while j > 0:
		z = mex
		pp = j
		for i in range(n):
			if mex == i and a[i] != i:
				if a[i] <= n:
					d[a[i]] -= 1
				p = a[i]
				a[i] = mex
				d[mex] += 1
				ans.append(i + 1)
				mex = d.index(0)
				j -= 1
		if pp == j:
			for i in range(n):
				if a[i] != i:
					if a[i] <= n:
						d[a[i]] -= 1
						d[n] += 1
						a[i] = n
						ans.append(i + 1)
						break
		mex = d.index(0)
		tle += 1
	if len(ans) > 2 * n:
		print('OHHO')
		exit(0)
	print(len(ans))
	print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	operation = []
	while True:
		isNonDecreasing = True
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				isNonDecreasing = False
				break
		if isNonDecreasing:
			break
		isNIn = [False] * (n + 1)
		for elem in a:
			isNIn[elem] = True
		for i in range(n + 1):
			if isNIn[i] == False:
				MEX = i
				break
		if MEX == n:
			for i in range(n):
				if a[i] != i and a[i] != n:
					break
			operation.append(str(i + 1))
			a[i] = n
		else:
			operation.append(str(MEX + 1))
			a[MEX] = MEX
	print(len(operation))
	if len(operation) != 0:
		print(' '.join(operation))


import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if sorted(a) == a:
		print(0)
		print()
		continue
	l = []
	c = 0
	while True:
		l1 = [0] * (n + 1)
		for j in a:
			l1[j] = 1
		mex = l1.index(0)
		ind = mex
		if mex == n:
			for j in range(n):
				if a[j] != j:
					ind = j
					break
		l.append(ind + 1)
		a[ind] = mex
		c += 1
		if sorted(a) == a:
			break
	print(c)
	print(*l)


def _mex(a):
	s = set(a)
	i = 0
	while i in s:
		i += 1
	return i

def is_sorted(a):
	for i in range(len(a) - 1):
		if a[i] > a[i + 1]:
			return False
	return True

def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = []
	for i in range(2 * n):
		if is_sorted(a):
			break
		mex = _mex(a)
		if mex < n:
			a[mex] = mex
			ans.append(mex + 1)
		else:
			for i in range(n):
				if a[i] != i:
					ans.append(i + 1)
					a[i] = mex
					break
	print(len(ans))
	print(*ans)
t = int(input())
for _ in range(t):
	solve()


def check():
	global a, n
	for i in range(1, n):
		if a[i] < a[i - 1]:
			return 1
	return 0
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	steps = []
	while check():
		mex = 0
		val = [0] * (n + 2)
		for i in range(n):
			val[a[i]] += 1
		for i in range(n + 2):
			if val[i] == 0:
				mex = i
				break
		if mex == n:
			ind = -1
			for i in range(n + 2):
				if val[i] > 1:
					ind = a.index(i)
					break
			for i in range(n):
				if a[i] != i and ind == -1:
					ind = a.index(i)
					break
			a[ind] = n
			steps += [ind + 1]
		else:
			a[mex] = mex
			steps += [mex + 1]
	print(len(steps))
	print(*steps)


def mex_func(a):
	vis = [0] * (n + 1)
	for elem in a:
		vis[elem] = 1
	for i in range(n + 1):
		if vis[i] == 0:
			return i
	return 0

def incorrect(a, n):
	for i in range(n):
		if a[i] != i:
			return i
	return 0

def inc(a):
	for i in range(n - 1):
		if a[i + 1] - a[i] < 0:
			return False
	return True
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	while inc(a) == False:
		mex = mex_func(a)
		incor = incorrect(a, n)
		if mex == n:
			a[incor] = n
			ans.append(incor + 1)
		else:
			a[mex] = mex
			ans.append(mex + 1)
	print(len(ans))
	print(*ans)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
mod = int(1000000000.0) + 7
i = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())

def mex(arr2):
	arr2.sort()
	st = 0
	for i in range(len(arr2)):
		if arr2[i] == st:
			st += 1
	return st
t = i()
for _ in range(t):
	n = int(input())
	arr = list(inp())
	pt = []
	for i in range(n):
		if arr[i] != i:
			pt.append(i)
	ans = []
	temp = [i for i in range(n)]
	while True:
		if temp == arr:
			break
		ch = mex(list(arr))
		if ch == n:
			for i in range(n):
				if arr[i] != i:
					pos = i
					break
			arr[pos] = n
			ans.append(pos)
			ch = mex(list(arr))
			arr[ch] = ch
			ans.append(ch)
		else:
			arr[ch] = ch
			ans.append(ch)
	ans = [i + 1 for i in ans]
	print(len(ans))
	print(*ans)


from sys import stdin
input = stdin.buffer.readline
for _ in range(int(input())):
	n = int(input())
	vis = [0] * (n + 1)
	ans = []
	(*b,) = map(int, input().split())
	for i in b:
		vis[i] += 1
	j = 0
	u = set((i for i in range(n) if b[i] != i))
	while u:
		for i in range(n + 1):
			if not vis[i]:
				mx = i
				break
		if mx == n:
			c = u.pop()
			u.add(c)
			vis[b[c]] -= 1
			b[c] = mx
			vis[mx] += 1
			ans.append(c + 1)
			for i in range(n + 1):
				if not vis[i]:
					mx = i
					break
		u.remove(mx)
		vis[b[mx]] -= 1
		b[mx] = mx
		vis[mx] += 1
		ans.append(mx + 1)
	print(len(ans))
	print(*ans)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from collections import defaultdict
graph = []
visited = []
arr = []
ans = []

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = list(map(int, input().split()))
		ans = []
		pt = 0
		while pt < n:
			mex = 0
			s = set()
			ind = -1
			if arr[pt] != pt:
				for i in range(n):
					s.add(arr[i])
					while mex in s:
						mex += 1
					if arr[i] == pt and ind == -1:
						ind = i
				if mex == pt:
					if arr[pt] != mex:
						arr[pt] = mex
						ans.append(pt)
					pt += 1
				else:
					assert ind != -1
					if mex < n:
						arr[mex] = mex
						ans.append(mex)
					else:
						arr[ind] = mex
						ans.append(ind)
			else:
				pt += 1
		for i in range(1, n):
			assert arr[i] >= arr[i - 1]
		for i in range(len(ans)):
			ans[i] += 1
		print(len(ans))
		print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	n = int(input())
	list1 = list(map(int, input().strip().split()))
	m = dict()
	for i in range(n + 1):
		m[i] = list1.count(i)
	mexx = []
	for i in range(n + 1):
		if m[i] == 0:
			mexx.append(i)
	ans = []
	while 1:
		mex = min(mexx)
		mexx.remove(mex)
		if mex == n:
			b = 0
			for i in range(n):
				if list1[i] != i:
					b = 1
					break
			if b == 0:
				break
			else:
				temp = list1[i]
				list1[i] = mex
				ans.append(i)
				m[temp] -= 1
				m[mex] += 1
				if m[temp] == 0:
					mexx.append(temp)
		else:
			temp = list1[mex]
			list1[mex] = mex
			ans.append(mex)
			m[temp] -= 1
			m[mex] += 1
			if m[temp] == 0:
				mexx.append(temp)
	print(len(ans))
	for val in ans:
		print(val + 1, end=' ')
	print()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	for _ in range(N()):
		n = N()
		arr = RLL()
		vis = [0] * n
		rec = [0] * (n + 1)
		for i in range(n):
			rec[arr[i]] += 1
		res = []
		while True:
			for i in range(n):
				if arr[i] == i:
					vis[i] = 1
					continue
				if rec[i] == 0:
					rec[arr[i]] -= 1
					arr[i] = i
					rec[i] += 1
					vis[i] = 1
					res.append(i + 1)
					break
			else:
				break
		while 0 in vis:
			for i in range(n):
				if vis[i] == 0:
					vis[i] = n
					rec[arr[i]] -= 1
					res.append(i + 1)
					b = i
					while arr[i] != i:
						res.append(arr[i] + 1)
						vis[arr[i]] = 1
						arr[i] = arr[arr[i]]
					res.append(b + 1)
		print(len(res))
		print(*res)
main()


import sys
import math
from math import factorial, inf, gcd
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
sys.setrecursionlimit(10 ** 5)

def mex(h, n):
	for i in range(n + 1):
		if i not in h:
			return i
t = 1
t = int(input())
for ii in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	h = Counter(a)
	ans = []
	while True:
		m = mex(h, n)
		if m == n:
			f = True
			for j in range(n - 1):
				if a[j] > a[j + 1]:
					ans.append(j)
					h[a[j]] -= 1
					if h[a[j]] == 0:
						del h[a[j]]
					h[m] += 1
					a[j] = m
					f = False
					break
			if f:
				break
			continue
		ans.append(m)
		h[a[m]] -= 1
		if h[a[m]] == 0:
			del h[a[m]]
		h[m] += 1
		a[m] = m
	print(len(ans))
	for i in ans:
		print(i + 1, end=' ')
	print()


def mex():
	s = set(ar)
	mex = 0
	while mex in s:
		mex += 1
	return mex

def matching():
	for i in range(n):
		if ar[i] != i:
			return i
	return -1

def solve(n, ar):
	ans = []
	for i in range(2 * n):
		m = mex()
		if m == n:
			ind = matching()
			if ind == -1:
				break
			ar[ind] = m
			ans.append(ind + 1)
		elif m < n:
			ar[m] = m
			ans.append(m + 1)
	print(len(ans))
	print(' '.join(map(str, ans)))
t = int(input())
for _ in range(t):
	n = int(input())
	ar = list(map(int, input().split()))
	solve(n, ar)


from sys import stdin, stdout
import sys
from math import *

def c(ar):
	l = ar.copy()
	l.sort()
	x = 0
	for i in range(len(ar)):
		if l[i] < x:
			continue
		elif l[i] == x:
			x += 1
		else:
			return x
	return x
for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	x = 0
	ans = []
	while sorted(ar) != ar:
		t = c(ar)
		if t == n:
			for i in range(n):
				if ar[i] != i:
					ar[i] = t
					ans.append(i + 1)
					break
		else:
			ar[t] = t
			ans.append(t + 1)
	print(len(ans))
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = list(range(n))
	d = [0] * (n + 1)
	for i in range(n):
		d[l[i]] += 1
	k = 0
	rs = []
	while l != l1:
		k += 1
		f = n
		for i in range(n + 1):
			if d[i] == 0:
				f = i
				d[f] += 1
				break
		if f == n:
			for i in range(n):
				if l[i] != i:
					rs.append(i + 1)
					d[l[i]] -= 1
					l[i] = f
					break
		else:
			rs.append(f + 1)
			d[l[f]] -= 1
			l[f] = f
	print(k)
	print(*rs)


import sys
import math
import heapq
from collections import defaultdict, deque
from decimal import *

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))

def isNotNormal(arr):
	for i in range(len(arr)):
		if i != arr[i]:
			return True
	return False

def update(exists, n):
	for i in range(n + 1):
		if exists[i] == 0:
			return i
for _ in range(r()):
	n = r()
	a = rl()
	exists = defaultdict(int)
	res = True
	for i in range(1, n):
		if a[i] < a[i - 1]:
			res = False
			break
	if res:
		print(0)
		print()
		continue
	ans = []
	for i in range(n):
		exists[a[i]] += 1
	mex = update(exists, n)
	while isNotNormal(a):
		if mex == n:
			for i in range(n):
				if i != a[i]:
					exists[a[i]] -= 1
					a[i] = mex
					exists[a[i]] += 1
					ans.append(i + 1)
					break
		else:
			exists[a[mex]] -= 1
			a[mex] = mex
			exists[a[mex]] += 1
			ans.append(mex + 1)
		mex = update(exists, n)
	print(len(ans))
	print(*ans)


class MEX:

	def __init__(self, n):
		self.i = [0] * (n + 1)
		self.l = n + 1
		self.m = 0

	def __getitem__(self, item):
		return self.i[item]

	def __setitem__(self, key, value):
		self.i[key] = value
		if key < self.m and value == 0:
			self.m = key
		elif key == self.m and value != 0:
			while self.m < self.l and self.i[self.m] != 0:
				self.m += 1

	def mex(self):
		return self.m

	def __call__(self):
		return self.m

class ListWithMEX:

	def __init__(self, iterable, n):
		self.list = iterable
		self.mex = MEX(n)
		self.l = n
		for v in iterable:
			self.mex[v] += 1
		self.history = []

	def step(self):
		v = self.mex()
		if v == self.l:
			for i in range(self.l):
				if self.list[i] != i:
					break
			else:
				return True
			self.mex[self.list[i]] -= 1
			self.mex[v] += 1
			self.list[i] = v
			self.history.append(i + 1)
		else:
			self.mex[self.list[v]] -= 1
			self.mex[v] += 1
			self.list[v] = v
			self.history.append(v + 1)

def solve():
	n = int(input())
	a = ListWithMEX(list(map(int, input().split())), n)
	while not a.step():
		pass
	print(len(a.history))
	print(*a.history)
for _ in range(int(input())):
	solve()


def non_decreasing(n, l):
	a = l[0]
	x = True
	for i in range(1, n):
		if a <= l[i]:
			a = l[i]
		else:
			x = False
			break
	return x
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = []
	while not non_decreasing(n, l):
		mex = 0
		while mex in l:
			mex += 1
		if mex < n:
			m.append(mex + 1)
			l[mex] = mex
		if mex == n:
			for i in range(n):
				if l[i] != i:
					m.append(i + 1)
					l[i] = mex
					break
	print(len(m))
	print(*m)


def mex(arr, l):
	for i in range(l + 1):
		if i not in arr:
			return i

def solve(arr, l):
	ops = []
	while arr != list(range(l)):
		tgt = mex(arr, l)
		if tgt == l:
			z = 0
			for i in arr:
				if i != z:
					idx = z
					break
				z += 1
		else:
			idx = tgt
		arr[idx] = tgt
		ops.append(idx + 1)
	return ops
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	a = [str(i) for i in solve(a, n)]
	print(len(a))
	print(' '.join(a))


from sys import stdin
input = stdin.readline
INF = 10 ** 9 + 7
MAX = 10 ** 7 + 7
MOD = 10 ** 9 + 7
for Ti in range(int(input().strip())):
	n = int(input().strip())
	c = [0] * (n + 1)
	ans = []
	a = [int(x) for x in input().strip().split()]
	for ai in a:
		c[ai] += 1

	def findMex():
		for (i, ci) in enumerate(c):
			if not ci:
				return i
	for i in range(2 * n):
		mex = findMex()
		ci = mex
		if mex == n:
			ci = 0
			while ci < n:
				if ci != a[ci]:
					break
				ci += 1
		if ci >= n:
			break
		c[a[ci]] -= 1
		c[mex] += 1
		a[ci] = mex
		ans.append(ci + 1)
	print(len(ans))
	print(*ans)


T = int(input())

def find(count):
	for i in range(len(count)):
		if count[i] == 0:
			return i
while T > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	count = [0] * (n + 1)
	for i in range(n):
		count[arr[i]] += 1
	op = []
	for i in range(2 * n):
		miss = find(count)
		if miss == n:
			x = True
			for j in range(n):
				if arr[j] != j:
					x = False
					count[arr[j]] -= 1
					count[miss] += 1
					arr[j] = miss
					op.append(j + 1)
					break
			if x is True:
				break
		else:
			temp = arr[miss]
			count[temp] -= 1
			count[miss] += 1
			arr[miss] = miss
			op.append(miss + 1)
	print(len(op))
	print(*op)
	T -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	b = set([i for i in range(n + 1)])
	while True:
		ind = sorted(list(b - set(a)))[0]
		if ind == n:
			break
		if a[ind] == ind:
			break
		else:
			a[ind] = ind
			ans.append(ind + 1)
	k = 0
	count = [0] * (n + 1)
	for i in range(n):
		count[a[i]] += 1
	for i in range(n):
		if a[i] == i:
			continue
		if count[i] == 0:
			ans.append(i + 1)
			count[a[i]] -= 1
			count[i] += 1
			a[i] = i
			k += 1
		else:
			num = list(b - set(a))
			num.sort(reverse=True)
			for j in range(i + 1, n):
				if a[j] == i:
					next = num.pop()
					count[next] += 1
					count[a[j]] -= 1
					a[j] = next
					k += 1
					ans.append(j + 1)
			if sorted(a[i:]) == a[i:]:
				break
			count[a[i]] -= 1
			count[i] += 1
			a[i] = i
			ans.append(i + 1)
			k += 1
	print(len(ans))
	print(' '.join(map(str, ans)))


import math
for _ in range(int(input())):
	am = int(input())
	arr = list(map(int, input().split()))
	was = [0] * (am + 1)
	for i in range(am):
		was[arr[i]] += 1
	out = []
	fl = False
	for i in range(am * 2):
		if fl:
			break
		for g in range(len(was)):
			if was[g] == 0:
				if g == len(was) - 1:
					for j in range(am - 1):
						if arr[j] > arr[j + 1]:
							break
					else:
						fl = True
						break
					for j in range(am):
						if arr[j] != j:
							was[arr[j]] -= 1
							was[g] += 1
							arr[j] = g
							out.append(j + 1)
							break
				else:
					was[g] += 1
					was[arr[g]] -= 1
					arr[g] = g
					out.append(g + 1)
					break
	print(len(out))
	print(*out)


def solved(arr):
	n = len(arr)
	for i in range(n):
		if i + 1 == arr[i]:
			continue
		else:
			return False
	return True

def nex(arr):
	n = len(arr)
	visit = [False for i in range(n + 1)]
	for e in arr:
		visit[e] = True
	for (i, e) in enumerate(visit):
		if not visit[i]:
			return i
t = int(input())
while t:
	t -= 1
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = []
	while not solved(arr):
		a = nex(arr)
		n = len(arr)
		if a == 0:
			for i in range(n):
				if arr[i] != i + 1:
					ans.append(i + 1)
					arr[i] = a
					break
		else:
			arr[a - 1] = a
			ans.append(a)
	print(len(ans))
	print(*ans)


from sys import exit, stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
from heapq import *

def op(i):
	global a, ra, ops, free
	ops.append(i + 1)
	old_a = a[i]
	new_a = heappop(free)
	a[i] = new_a
	ra[old_a].remove(i)
	ra[new_a].add(i)
	if not ra[old_a]:
		heappush(free, old_a)
(T,) = rl()
for _ in range(T):
	(n,) = rl()
	a = rl()
	ra = [set() for x in range(n + 1)]
	for (i, x) in enumerate(a):
		ra[x].add(i)
	free = []
	for x in range(n + 1):
		if not ra[x]:
			heappush(free, x)
	ops = []
	for i in range(n):
		while free[0] < n:
			op(free[0])
		if a[i] != i:
			j = next(iter(ra[i]))
			op(j)
			op(i)
	print(len(ops))
	print(*ops)


def mex(l):
	s = set(l)
	for i in range(len(l) + 1):
		if i not in s:
			return i
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	k = 0
	j = 0
	x = []
	while j < n:
		m = mex(a)
		if m == n:
			while j < n and a[j] == j:
				j += 1
			if j < n:
				k += 1
				x += [j + 1]
				a[j] = m
		else:
			k += 1
			x += [m + 1]
			a[m] = m
	print(k)
	print(*x)


def mex(ar):
	i = 0
	while ar[i]:
		i += 1
	return i
for o in range(int(input())):
	n = int(input())
	ile = [0] * (n + 1)
	a = list(map(int, input().split()))
	for i in a:
		ile[i] += 1
	aa = []
	for i in range(2 * n):
		m = mex(ile)
		if m == n:
			for j in range(n):
				if j != a[j]:
					ile[a[j]] -= 1
					ile[m] += 1
					a[j] = m
					aa.append(j + 1)
					break
			else:
				break
		else:
			ile[a[m]] -= 1
			ile[m] += 1
			a[m] = m
			aa.append(m + 1)
	print(len(aa))
	print(*aa)


def mex(s):
	for i in range(n):
		if i not in s:
			return i
	return n
for u in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	l = []
	out = []
	for i in range(n):
		if s[i] != i:
			l.append(i)
	while l != []:
		temp = mex(s)
		if temp == n:
			s[l[0]] = n
			out.append(l[0])
		elif temp in l:
			s[temp] = temp
			out.append(temp)
			l.remove(temp)
	print(len(out))
	for i in out:
		print(i + 1, end=' ')
	print()


import bisect
import sys
import math
input = sys.stdin.readline
import functools
import heapq
from collections import defaultdict
from collections import Counter

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def solve(case):
	n = inp()
	aa = inlt()
	c = Counter(aa)
	pq = []
	for i in range(0, n + 1):
		if c[i] == 0:
			heapq.heappush(pq, i)
	s = set(range(0, n))
	for i in range(0, n):
		if aa[i] == i:
			s.discard(i)
	res = 0
	res_arr = []
	while len(s) > 0:
		val = heapq.heappop(pq)
		idx = min(n - 1, val)
		if val == n and aa[-1] == n - 1:
			for idx in s:
				break
		c[aa[idx]] -= 1
		if c[aa[idx]] == 0:
			heapq.heappush(pq, aa[idx])
		aa[idx] = val
		c[val] += 1
		if aa[idx] == idx:
			s.discard(idx)
		res += 1
		res_arr.append(idx + 1)
	print(res)
	print(' '.join((str(v) for v in res_arr)))
if len(sys.argv) > 1 and sys.argv[1].startswith('input'):
	f = open('./' + sys.argv[1], 'r')
	input = f.readline
T = inp()
for i in range(T):
	res = solve(i + 1)


from collections import Counter

def solve():
	n = int(input())
	arr = [int(x) for x in input().split()]
	curr_set = Counter(arr)
	operations = []
	curr_mex = 0
	while curr_mex in curr_set:
		curr_mex += 1
	for i in range(n):
		x = arr[i]
		if curr_set[x] > 1:
			curr_set[x] -= 1
			operations.append(i + 1)
			arr[i] = curr_mex
			curr_set[curr_mex] += 1
			while curr_mex in curr_set:
				curr_mex += 1
	while len(operations) < 2 * n:
		if curr_mex < n:
			x = arr[curr_mex]
			curr_set.pop(x)
			arr[curr_mex] = curr_mex
			curr_set[curr_mex] += 1
			operations.append(curr_mex + 1)
			if x < curr_mex:
				curr_mex = x
			else:
				while curr_mex in curr_set:
					curr_mex += 1
		else:
			i = n - 1
			while arr[i] == i:
				i -= 1
			if i == -1:
				break
			x = arr[i]
			curr_set.pop(x)
			arr[i] = curr_mex
			curr_set[curr_mex] += 1
			operations.append(i + 1)
			if x < curr_mex:
				curr_mex = x
			else:
				while curr_mex in curr_set:
					curr_mex += 1
	print(len(operations))
	print(*operations)
for _ in range(int(input())):
	solve()


def replace(n, array):
	res = []
	pos = {}
	for i in range(n + 1):
		pos[i] = []
	for i in range(n):
		pos[array[i]].append(i)
	end = False
	while not end:
		for i in range(n + 1):
			if not pos[i]:
				mex = i
				break
		if mex < n:
			if array[mex] != mex:
				pos[array[mex]].remove(mex)
				array[mex] = mex
				pos[mex].append(mex)
				res.append(mex)
		else:
			j = 0
			while j < n:
				if array[j] != j:
					pos[array[j]].remove(j)
					array[j] = n
					pos[n].append(j)
					res.append(j)
					break
				j += 1
			if j == n:
				end = True
	for i in range(len(res)):
		res[i] += 1
	print(len(res))
	print(*res)
t = int(input())
for i in range(t):
	n = int(input())
	array = [int(s) for s in input().split()]
	replace(n, array)


def problemA():
	n = int(input())
	l = list(map(int, input().split()))
	for i in range(n):
		l[i] = (-1) ** i * abs(l[i])
	print(*l)

def problemB():
	(x, y) = list(map(int, input().split()))
	m = []
	for _ in range(x):
		m.append(list(map(int, input().split())))
	if m[0][0] > 2 or m[x - 1][y - 1] > 2 or m[0][y - 1] > 2 or (m[x - 1][0] > 2):
		print('NO')
		return
	for i in range(1, x - 1):
		if m[i][0] > 3 or m[i][y - 1] > 3:
			print('NO')
			return
	for i in range(1, y - 1):
		if m[0][i] > 3 or m[x - 1][i] > 3:
			print('NO')
			return
	for i in range(1, x - 1):
		for j in range(1, y - 1):
			if m[i][j] > 4:
				print('NO')
				return
	print('YES')
	m = []
	for _ in range(x):
		m.append([4] * y)
	m[0][0] = 2
	m[x - 1][y - 1] = 2
	m[x - 1][0] = 2
	m[0][y - 1] = 2
	for i in range(1, x - 1):
		m[i][0] = 3
		m[i][y - 1] = 3
	for i in range(1, y - 1):
		m[0][i] = 3
		m[x - 1][i] = 3
	for i in m:
		print(*i)

def problemC():
	n = int(input())
	l = list(map(int, input().split()))
	if l[0] < l[-1]:
		print('YES')
	else:
		print('NO')

def problemD():
	n = int(input())
	l = list(map(int, input().split()))
	c = [0] * (n + 1)
	for i in l:
		c[i] += 1
	a = []
	b = 0
	for _ in range(2 * n):
		i = 0
		while c[i] > 0:
			i += 1
		b += 1
		if i == n:
			i = 0
			while i < n and l[i] == i:
				i += 1
			if i == n:
				b -= 1
				break
			a.append(i + 1)
			c[l[i]] -= 1
			l[i] = n
			c[n] += 1
		else:
			a.append(i + 1)
			c[l[i]] -= 1
			l[i] = i
			c[i] += 1
	print(b)
	print(*a)
cases = int(input())
for _ in range(cases):
	problemD()


def mex(brr):
	s = set(brr)
	for i in range(1 + len(brr)):
		if i not in s:
			return i
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	k = 0
	j = 0
	res = []
	while j < n:
		tmp = mex(arr)
		if tmp == n:
			while j < n and arr[j] == j:
				j += 1
			if j < n:
				k += 1
				res += [j + 1]
				arr[j] = tmp
		else:
			k += 1
			res += [tmp + 1]
			arr[tmp] = tmp
	print(k)
	print(*res)


def get_mex(a):
	set_ = set(a)
	for i in range(10000):
		if i not in set_:
			return i
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	while True:
		mex = get_mex(a)
		if mex < n:
			a[mex] = mex
			ans.append(mex + 1)
		else:
			for i in range(n):
				if a[i] != i:
					a[i] = mex
					ans.append(i + 1)
					break
			else:
				break
	print(len(ans))
	print(*ans)


def mex(l, n):
	for i in range(n + 1):
		if i not in l:
			return i
			break
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	res = []
	k = [x for x in range(n)]
	while l != k:
		if mex(l, n) == n:
			for j in range(n):
				if l[j] != j:
					l[j] = mex(l, n)
					res.append(j + 1)
					break
		else:
			temp = mex(l, n)
			l[mex(l, n)] = temp
			res.append(temp + 1)
	print(len(res))
	for i in range(len(res)):
		if i == len(res) - 1:
			print(res[i], sep=' ')
		else:
			print(res[i], sep=' ', end=' ')


t = int(input())

def MEX(arr):
	vis = []
	for i in range(1002):
		vis.append(0)
	for i in range(len(arr)):
		vis[arr[i]] += 1
	for i in range(1002):
		if vis[i] == 0:
			return i
	return 1000
while t:
	n = int(input())
	arr = list(map(int, input().split()))
	mex = MEX(arr)
	k = 0
	ans = []
	while mex < n:
		arr[mex] = mex
		k += 1
		ans.append(mex)
		mex = MEX(arr)
	for i in range(len(arr)):
		if arr[i] != i:
			mex = MEX(arr)
			arr[i] = mex
			ans.append(i)
			k += 1
			mex = MEX(arr)
			while mex < n:
				arr[mex] = mex
				k += 1
				ans.append(mex)
				mex = MEX(arr)
	print(k)
	for i in range(k):
		print(ans[i] + 1, end=' ')
	print('')
	t -= 1


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n = mint()
	a = list(mints())
	c = [0] * (n + 1)
	for i in a:
		c[i] += 1
	r = []
	while True:
		ok = True
		for i in range(1, n):
			if a[i - 1] > a[i]:
				ok = False
				break
		if ok:
			break
		x = c.index(0)
		if x == n:
			for i in range(0, n):
				if a[i] != i:
					p = i
					break
		else:
			p = x
		c[a[p]] -= 1
		a[p] = x
		c[x] += 1
		r.append(p + 1)
	print(len(r))
	print(' '.join(map(str, r)))
for i in range(mint()):
	solve()


def function(arr, n):
	s = 0
	for i in range(n - 1):
		if arr[i + 1] < arr[i]:
			s += 1
			break
	if s == 1:
		return False
	return True

def anotherFunction(arr, n):
	lis = [0] * (n + 1)
	for i in range(n):
		lis[arr[i]] = 1
	a = lis.count(1)
	if (lis[-1] == 0 or lis[-2] == 0) and a == n:
		if arr[-1] == n or arr[-1] == n - 1:
			return True
		return False
	return False

def impFunction(arr, n):
	for i in range(n):
		if arr[i] != i:
			return i

def MEX(arr, n):
	lis = [0] * (n + 1)
	for i in range(n):
		lis[arr[i]] = 1
	for i in range(n + 1):
		if lis[i] == 0:
			return i
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = []
	for j in range(2 * n):
		b = function(arr, n)
		c = anotherFunction(arr, n)
		if b == True:
			break
		elif c == True:
			d = impFunction(arr, n)
			a = MEX(arr, n)
			arr[d] = a
			ans.append(d + 1)
		else:
			a = MEX(arr, n)
			if a != n:
				arr[a] = a
				ans.append(a + 1)
			else:
				arr[a - 1] = a
				ans.append(a)
	print(len(ans))
	print(' '.join((str(x) for x in ans)))


import time, math, bisect, sys, heapq
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x))

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 9 + 7

def MEX(li, n):
	visited = [False for i in range(n + 1)]
	for i in range(n):
		visited[li[i]] = True
	ind = visited.index(False)
	return ind

def solve():
	n = II()
	li = L()
	k = 0
	fn = []
	while True and k <= 2 * n:
		if sorted(li) == li:
			break
		else:
			mex = MEX(li, n)
			if mex != n:
				k += 1
				li[mex] = mex
				fn.append(mex + 1)
			else:
				for i in range(n):
					if li[i] != i:
						li[i] = n
						k += 1
						fn.append(i + 1)
						break
	print(k)
	print(*fn)
t = II()
for i in range(t):
	solve()


from sys import stdin
from collections import deque, Counter
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	se = Counter(arr)
	ops = []
	fl = 1
	backset = -1
	while fl:
		mex = -1
		fl = 0
		for x in range(n + 1):
			if not se[x] and mex == -1:
				mex = x
			if x < n - 1:
				if arr[x + 1] - arr[x] < 0:
					fl = 1
		if not fl:
			break
		if mex == n or mex == backset - 1:
			backset = mex
			se[arr[mex - 1]] -= 1
			arr[mex - 1] = mex
			se[mex] += 1
			ops.append(mex)
			continue
		se[arr[mex]] -= 1
		arr[mex] = mex
		se[mex] += 1
		ops.append(mex + 1)
	print(len(ops))
	for t in ops:
		print(t, end=' ')
	print('')


for tc in range(int(input())):
	n = int(input())
	A = input().split(' ')
	for i in range(n):
		A[i] = int(A[i])
	notinindex = []
	move = []
	for i in range(n):
		if A[i] != i:
			notinindex.append(i)
	while notinindex != []:
		B = min(set(range(n + 1)) - set(A))
		if B == n:
			move.append(notinindex[0] + 1)
			A[notinindex[0]] = n
		else:
			move.append(B + 1)
			A[B] = B
			notinindex.remove(B)
	print(len(move))
	for i in move:
		print(i, end=' ')
	print()


inp = lambda : map(int, input().split(' '))
(t,) = inp()
for _ in range(t):
	(n,) = inp()
	arr = list(inp())
	count = {i: 0 for i in range(n + 1)}
	mex = set()
	res = []
	for i in arr:
		count[i] += 1
	for (key, val) in count.items():
		if val == 0 and key != n:
			mex.add(key)
	while mex:
		val = min(mex)
		mex.remove(val)
		res.append(val)
		curr_val = arr[val]
		arr[val] = val
		count[curr_val] -= 1
		if count[curr_val] == 0 and curr_val != n:
			mex.add(curr_val)
	pos = [0 for i in range(n)]
	for (idx, val) in enumerate(arr):
		pos[val] = idx
	for (idx, val) in enumerate(arr):
		if idx != val:
			id_pos = pos[idx]
			res.append(id_pos)
			arr[id_pos] = n
			res.append(idx)
			curr_val = arr[idx]
			arr[idx] = idx
			while curr_val != n:
				temp = arr[curr_val]
				arr[curr_val] = curr_val
				res.append(curr_val)
				curr_val = temp
	print(len(res))
	res = [str(i + 1) for i in res]
	print(' '.join(res))


T = int(input())

def mex(n, a):
	p = [0] * ((n + 1) * 2)
	for i in range(n):
		p[a[i]] = 1
	return p.index(0)
for i in range(T):
	n = int(input())
	a = [int(i) for i in input().split()]
	a0 = list(a)
	if a == sorted(a):
		print(0)
		print()
		continue
	seen = [0] * ((n + 1) * 2)
	seen[n] = 1
	ops = 0
	opouts = []
	for i in range(n):
		if seen[a[i]]:
			opouts.append(str(i + 1))
			ops += 1
			a[i] = mex(n, a)
		else:
			seen[a[i]] = 1
	a1 = list(a0)
	for i in opouts:
		a1[int(i) - 1] = mex(n, a1)
	while a1 != sorted(a1):
		ne = False
		A = [0] * n
		for i in range(n):
			A[a1[i]] = i
		for i in range(n):
			if A[i] != i:
				ne = A[i]
				break
		nops = []
		if ne:
			i0 = 0
			val = ne
			orig = ne
			ops += 1
			nops.append(val + 1)
			opouts.append(str(val + 1))
			while orig != val or i0 == 0:
				i0 += 1
				val = a[val]
				ops += 1
				opouts.append(str(val + 1))
				nops.append(val + 1)
		for i in nops:
			a1[i - 1] = mex(n, a1)
	print(ops)
	print(' '.join(opouts))


import sys
input = sys.stdin.readline
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	l = RI()
	cur = -1
	ans = []
	temp = [0] * (n + 1)
	for j in l:
		temp[j] += 1
	i = 0
	while i < n:
		if l[i] == i:
			i += 1
			continue
		mex = n
		for j in range(0, n):
			if temp[j] == 0:
				mex = j
				break
		if mex == n:
			ans.append(i)
			temp[l[l[i]]] -= 1
			l[l[i]] = l[i]
			temp[l[i]] += 1
			ans.append(l[i])
			temp[l[i]] -= 1
			l[i] = n
			temp[l[i]] += 1
		else:
			ans.append(mex)
			temp[l[mex]] -= 1
			l[mex] = mex
			temp[mex] += 1
	print(len(ans))
	ans = [i + 1 for i in ans]
	print(*ans)


def mex(a):
	x = 0
	while x in a:
		x += 1
	return x

def test(a):
	for i in range(1, len(a)):
		if a[i - 1] > a[i]:
			return False
	return True

def main():
	(n,) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	op = []
	idx = 0
	val = -1
	while not test(a):
		while idx > 0 and (a[idx] == val or a[idx] == val + 1) or (idx == 0 and a[idx] == 0):
			val = a[idx]
			idx += 1
		m = mex(a)
		if m == n:
			m_idx = a.index(min(a[idx:]), idx)
		else:
			m_idx = m
		op.append(m_idx + 1)
		a[m_idx] = m
	print(len(op))
	if len(op):
		print(*op)
for _ in range(int(input())):
	main()


cases = int(input())
for i in range(cases):
	n = int(input())
	l2 = input().split(' ')
	arr = []
	for a in l2:
		arr.append(int(a))
	moves = 0
	test = arr[:]
	test.sort()
	if test == arr:
		print(0)
		print('')
		continue
	sample = []
	for j in range(n):
		sample.append(j)
	unfix = []
	miss = -1
	for l in range(len(arr)):
		ele1 = arr[l]
		ele2 = sample[l]
		if ele1 != ele2:
			unfix.append(l)
	index = []
	while arr != sample:
		for k in range(n + 1):
			if k not in arr:
				miss = k
				if miss == n:
					rand = unfix[0]
					index.append(str(rand + 1))
					arr[rand] = n
					moves += 1
					break
				elif miss < n:
					arr[miss] = miss
					index.append(str(miss + 1))
					unfix.remove(miss)
					moves += 1
					break
	print(moves)
	print(' '.join(index))


from sys import stdin, stdout
import math
from collections import defaultdict
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	steps = 0
	ans = []
	seen = set()
	while True:
		s1 = set(list(range(n + 1)))
		s2 = set(a)
		mex = min(s1 - s2)
		idx = mex
		if mex == n:
			idx -= 1
		elif (idx, mex + 1) in seen:
			idx -= 1
		a[idx] = mex
		seen.add((idx, mex))
		steps += 1
		ans.append(idx + 1)
		if all((a[i] <= a[i + 1] for i in range(n - 1))):
			break
	print(steps)
	if not ans:
		print('')
	else:
		print(' '.join(map(str, ans)))


t = int(input())
for j in range(t):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	d = dict()
	for i in range(n + 1):
		d[i] = 0
	for j in arr:
		d[j] = d[j] + 1
	mex = 0
	for i in range(n + 1):
		if d[i] == 0:
			mex = i
			break
	k = 0
	crr = []
	while k < 2 * n:
		if mex == n:
			flag = 0
			for i in range(n):
				if arr[i] != i:
					flag = 1
					break
			if flag == 1:
				t = arr[i]
				crr.append(i)
				arr[i] = mex
				d[t] = d[t] - 1
				d[mex] = d[mex] + 1
			elif flag == 0:
				break
		if mex < n:
			t = arr[mex]
			arr[mex] = mex
			d[t] = d[t] - 1
			d[mex] = d[mex] + 1
			crr.append(mex)
		k = k + 1
		for i in range(n + 1):
			if d[i] == 0:
				mex = i
				break
	print(k)
	for i in crr:
		print(i + 1, end=' ')
	print(' ')


from sys import stdin, stdout

def mex(ary):
	n = len(ary)
	track = [False] * (n + 1)
	for elem in ary:
		track[elem] = True
	return track.index(False)

def unfixed(ary):
	for i in range(len(ary)):
		if i != ary[i]:
			return i
	return -1

def main():
	t = int(stdin.readline())
	for test in range(t):
		n = int(stdin.readline())
		ary = list(map(int, stdin.readline().split()))
		neq = 0
		idxs = []
		(k, ops) = (0, [])
		for i in range(n):
			if ary[i] != i:
				neq += 1
				idxs.append(i)
		while True:
			m = mex(ary)
			if m == n:
				j = unfixed(ary)
				if j == -1:
					break
				ary[j] = n
				ops.append(j + 1)
			else:
				ary[m] = m
				ops.append(m + 1)
			k += 1
		stdout.write(str(k) + '\n')
		stdout.write(' '.join(map(str, ops)))
		stdout.write('\n')
	return
main()


import sys
import math
from decimal import *

def I():
	return int(sys.stdin.readline())

def IL():
	return list(map(int, sys.stdin.readline().strip().split()))

def ILS():
	return list(map(str, sys.stdin.readline().strip().split()))

def mex(l):
	n = len(l) + 1
	p = [0] * n
	for ll in l:
		if ll >= 0 and ll < n:
			p[ll] = 1
	for i in range(len(p)):
		if p[i] == 0:
			return i
	return None

def check(l):
	for i in range(1, len(l)):
		if l[i] < l[i - 1]:
			return True
	return False

def solve():
	tt = I()
	for ii in range(tt):
		n = I()
		l = IL()
		ans = []
		cnt = 0
		idx = len(l) - 1
		while check(l):
			xx = mex(l)
			x = xx
			if x == None or x >= len(l):
				x = idx
				while x == l[x]:
					x -= 1
					idx = x
			if x < 0:
				break
			cnt += 1
			ans.append(x)
			l[x] = xx
		print(cnt)
		for aa in ans:
			print(aa + 1, end=' ')
		print()
solve()


t = int(input())
for case in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	x = []
	k = 0
	realMex = 0
	for i in range(n):
		for j in range(n + 1):
			if j in a:
				continue
			else:
				realMex = j
				break
		final = False
		if realMex == n:
			final = True
			for i in range(n):
				if i != a[i]:
					x.append(i + 1)
					k += 1
					realMex = a[i]
					a[i] = n
					final = False
					break
			if final == True:
				break
		for j in range(n + 1):
			if final == True:
				break
			if j in a:
				continue
			else:
				realMex = j
				break
		x.append(realMex + 1)
		k += 1
		a[realMex] = realMex
	print(k)
	print(*x)


from sys import *
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = [0] * (n + 1)
	for i in a:
		d[i] += 1
	ans = []
	while 1:
		k = -1
		for i in range(n + 1):
			if d[i] == 0:
				k = i
				break
		if k == n:
			unindexed = -1
			for i in range(n):
				if a[i] != i:
					unindexed = i
					break
			if unindexed != -1:
				d[a[unindexed]] -= 1
				d[k] += 1
				a[unindexed] = k
				ans.append(unindexed + 1)
			else:
				break
		else:
			d[a[k]] -= 1
			a[k] = k
			d[k] += 1
			ans.append(k + 1)
	print(len(ans))
	print(*ans)


import math
import sys
from itertools import permutations
input = sys.stdin.readline
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = []
	while True:
		flag = True
		for j in range(1, n):
			if arr[j] < arr[j - 1]:
				flag = False
				break
		if flag:
			break
		mex = [False] * (n + 1)
		for k in range(n):
			mex[arr[k]] = True
		cur = 0
		for k in range(n + 1):
			if mex[k] == False:
				cur = k
				break
		if cur == n:
			for k in range(n):
				if arr[k] != k:
					arr[k] = cur
					ans.append(k + 1)
					break
		else:
			arr[cur] = cur
			ans.append(cur + 1)
	print(len(ans))
	print(*ans)


import sys
import math as mt
input = sys.stdin.buffer.readline

def get_mex(l, n):
	d1 = {}
	for i in l:
		d1[i] = 1
	for i in range(n):
		if d1.get(i, -1) == -1:
			return i
	return n
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	mex = get_mex(l, n)
	ans = []
	for i1 in range(2 * n):
		mex = get_mex(l, n)
		if mex == n:
			ind = -1
			for i in range(n):
				if l[i] != i:
					ind = i
					break
			if ind != -1:
				ans.append(ind + 1)
				l[ind] = mex
		else:
			ans.append(mex + 1)
			l[mex] = mex
	print(len(ans))
	print(*ans)


def mex(arr):
	arr.sort()
	mx = 0
	for a in arr:
		if a <= mx:
			mx = a + 1
	return mx
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split(' ')))
	dab = []
	for (i, a) in enumerate(arr):
		dab.append((a, i))
	dab.sort()
	ans = []
	vis = [False for i in range(n)]
	for i in range(2 * n):
		if sorted(arr) == arr:
			break
		mx = mex(arr.copy())
		if mx == n:
			for j in range(n):
				if not vis[j]:
					vis[j] = True
					arr[j] = mx
					ans.append(j + 1)
					break
		else:
			arr[mx] = mx
			vis[mx] = True
			ans.append(mx + 1)
	print(len(ans))
	print(*ans)


t = int(input())
cases = []
for i in range(t):
	n = int(input())
	cases.append(list(map(int, input().strip().split())))

def solve(case):
	nonfixed = []
	for (i, n) in enumerate(case):
		if i != n:
			nonfixed.append(i)
	if len(nonfixed) == 0:
		print('0')
		print('')
		return
	steps = 0
	outst = ''
	while len(nonfixed) > 0:
		steps += 1
		mex = set(range(len(case) + 1))
		for n in case:
			if n in mex:
				mex.remove(n)
		mex = min(mex)
		if mex == len(case):
			case[nonfixed[0]] = mex
			outst += str(1 + nonfixed[0]) + ' '
		else:
			case[mex] = mex
			outst += str(mex + 1) + ' '
			nonfixed.remove(mex)
	print(steps)
	print(outst)
for case in cases:
	solve(case)


def freq_dict(a):
	d = {}
	for i in a:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	return d

def find_mex(n, d):
	for i in range(n + 1):
		if i not in d:
			return i

def is_sorted(n, l):
	for i in range(1, n):
		if l[i] < l[i - 1]:
			return i - 1
	return -1

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(map(int, input().split()))
		d = freq_dict(a)
		printl = []
		while True:
			bad_idx = is_sorted(n, a)
			if bad_idx == -1:
				break
			mex = find_mex(n, d)
			if mex == n:
				to_go = bad_idx
			else:
				to_go = mex
			printl.append(to_go + 1)
			d[a[to_go]] -= 1
			if d[a[to_go]] == 0:
				del d[a[to_go]]
			if mex in d:
				d[mex] += 1
			else:
				d[mex] = 1
			a[to_go] = mex
		print(len(printl))
		print(*printl)
main()


import sys
input = sys.stdin.readline
t = int(input())
for q in range(t):
	n = int(input())
	ans = []
	fixed = [False for i in range(n)]
	a = [int(x) for x in input().split()]
	while True:
		for i in range(n):
			if a[i] != i:
				k = set(a)
				mex = 0
				while mex in a:
					mex += 1
				if mex >= n:
					for j in range(n):
						if fixed[j] == False:
							ans.append(j + 1)
							a[j] = mex
							break
				else:
					ans.append(mex + 1)
					a[mex] = mex
					fixed[mex] = True
			else:
				fixed[i] = True
		br = True
		for i in range(n):
			if fixed[i] == False:
				br = False
		if br:
			break
	print(len(ans))
	print(*ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def update_mex(tracker):
	t1 = 0
	for b in range(len(tracker)):
		if tracker[b] < 1:
			t1 = b
			break
	return t1
testcases = int(input())
for j in range(testcases):
	n = int(input())
	vals = list(map(int, input().split()))
	tracker = [0] * (n + 2)
	mex = 0
	for s in range(n):
		tracker[vals[s]] += 1
	mex = update_mex(tracker)
	moves = 0
	outy = []
	for s in range(n):
		if mex > n - 1:
			break
		elif vals[mex] != mex:
			tracker[vals[mex]] -= 1
			vals[mex] = mex
			tracker[mex] += 1
			moves += 1
			outy.append(mex + 1)
			mex = update_mex(tracker)
	cv = 0
	while cv <= n - 1:
		found = False
		for s in range(n):
			if s != cv:
				if vals[s] == cv:
					tracker[vals[s]] -= 1
					vals[s] = mex
					tracker[mex] += 1
					moves += 1
					outy.append(s + 1)
					if found == False:
						mex = update_mex(tracker)
					found = True
		if vals[cv] != cv:
			tracker[vals[cv]] -= 1
			vals[cv] = cv
			tracker[cv] += 1
			outy.append(cv + 1)
			moves += 1
		mex = update_mex(tracker)
		cv += 1
	print(moves)
	print(*outy)


for i in range(int(input())):
	n = int(input())
	a = [int(w) for w in input().split()]
	b = []
	d = []
	e = 0
	go = True
	for m in range(n):
		if m != a[m]:
			b.append(m + 1)
	x = len(b)
	if x == 0:
		print(e)
		print(*d)
	else:
		for l in range(2 * n + 1):
			go = True
			for p in range(n + 1):
				if p not in a:
					if p == n:
						d.append(b[0])
						a[b[0] - 1] = p
						e += 1
						x += 1
						go = False
						break
					else:
						a[p] = p
						d.append(p + 1)
						b.remove(p + 1)
						e += 1
						go = False
						break
			if e == x:
				print(e)
				print(*d)
				break


def main():
	n = int(input())
	a = list(map(int, input().split()))
	dct = dict()
	changes = []
	for i in range(2 * n):
		st = []
		for k in range(n + 1):
			st.append(k)
		st = set(st)
		for k in range(n):
			if a[k] in st:
				st.remove(a[k])
		change = min(st)
		if change == n:
			for k in range(n):
				if a[k] != k:
					changes.append(k)
					a[k] = n
					break
		else:
			a[change] = change
			changes.append(change)
		end = True
		for k in range(n):
			if a[k] != k:
				end = False
				break
		if end:
			break
	print(len(changes))
	for i in changes:
		print(i + 1, end=' ')
	print()
t = int(input())
for i in range(t):
	main()


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(io.IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	Cnt = [0] * (N + 1)
	for a in A:
		Cnt[a] += 1
	Ans = []
	for _ in range(2 * N):
		for (idx_Cnt, c) in enumerate(Cnt):
			if c == 0:
				break
		c = idx_Cnt
		if c != N:
			Cnt[A[c]] -= 1
			A[c] = c
			Cnt[c] += 1
			Ans.append(c + 1)
		else:
			for (idx_A, a) in enumerate(A):
				if idx_A != a:
					break
			else:
				break
			Cnt[A[idx_A]] -= 1
			A[idx_A] = N
			Cnt[N] += 1
			Ans.append(idx_A + 1)
	print(len(Ans))
	print(' '.join(map(str, Ans)))


from __future__ import division, print_function
import itertools, os, sys, threading
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from math import sqrt, floor, factorial, gcd, log
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from math import gcd
from bisect import bisect
from random import randrange
input = lambda : sys.stdin.readline().rstrip('\r\n')
read = lambda : list(map(int, input().strip().split(' ')))

def main():
	for _ in range(int(input())):
		n = int(input())
		arr = read()
		que = deque()
		vis = [0] * (n + 1)
		for i in arr:
			vis[i] += 1
		ans_arr = []
		for i in range(2 * n):
			mex = vis.index(0)
			if mex < n:
				vis[arr[mex]] -= 1
				vis[mex] += 1
				arr[mex] = mex
				ans_arr.append(mex + 1)
			else:
				for ind in range(n):
					if arr[ind] != ind:
						break
				vis[arr[ind]] -= 1
				vis[mex] += 1
				arr[ind] = mex
				ans_arr.append(ind + 1)
		print(len(ans_arr))
		print(*ans_arr)
main()


def mex(a):
	i = 0
	while i <= len(a):
		if i not in a:
			return i
		i += 1
t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	res = []
	init = n - 1
	for j in range(2 * n):
		k = mex(set(b))
		if k == init + 1 and init >= 0:
			b[init] = k
			res.append(init + 1)
			init -= 1
		else:
			b[k] = k
			res.append(k + 1)
	print(len(res))
	print(*res)


tc = int(input())
for i in range(tc):
	n = int(input())
	a = list(map(int, input().split()))
	fr = [0] * (n + 2)
	for i in a:
		fr[i] += 1
	v = []
	mex = int(0)
	for i in range(0, 2 * n):
		f = 0
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				f = 1
		if f == 0:
			break
		for i in range(0, n + 1):
			if fr[i] == 0:
				mex = i
				break
		if mex == n:
			for i in range(n):
				if a[i] != i:
					fr[a[i]] -= 1
					a[i] = mex
					fr[mex] += 1
					v.append(i + 1)
					break
		else:
			fr[a[mex]] -= 1
			a[mex] = mex
			fr[mex] += 1
			v.append(mex + 1)
	print(len(v))
	for i in v:
		print(i, end=' ')
	print()


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n,) = I()
	l = I()

	def ck(ar):
		for i in range(1, len(ar)):
			if ar[i - 1] > ar[i]:
				return 1
		return 0

	def mex(ar):
		ar = [-1] + sorted(ar)
		for i in range(1, len(ar)):
			if ar[i - 1] != ar[i] and ar[i - 1] + 1 != ar[i]:
				return ar[i - 1] + 1
		return max(ar) + 1
	an = []
	ct = 0
	p = 0
	while ck(l) and ct < 2 * n:
		cm = mex(l)
		if cm == n:
			for i in range(n):
				if l[i] != i:
					l[i] = cm
					an.append(i)
					break
		else:
			l[cm] = cm
			an.append(cm)
		ct += 1
	for i in range(len(an)):
		an[i] += 1
	print(len(an))
	print(*an)


from collections import defaultdict

def mex(ad, n):
	for i in range(n + 1):
		if i not in ad or ad[i] == 0:
			return i

def update(ad, old_value, new_value):
	ad[old_value] -= 1
	ad[new_value] += 1

def valid(a):
	for i in range(n - 1):
		if a[i] > a[i + 1]:
			return False
	return True

def find(a, n):
	for i in range(n - 1, -1, -1):
		if a[i] != i:
			return i
	return None

def solve(a, n):
	k = 0
	ans = []
	ad = defaultdict(int)
	for x in a:
		ad[x] += 1
	while True:
		if valid(a):
			break
		if k >= 2 * n:
			break
		m = mex(ad, n)
		k += 1
		if m < n:
			prev = a[m]
			a[m] = m
			update(ad, prev, m)
			ans.append(m + 1)
		else:
			i = find(a, n)
			prev = a[i]
			a[i] = n
			update(ad, prev, n)
			ans.append(i + 1)
	return (k, ans)
t = int(input())
for case in range(t):
	n = int(input())
	a = [int(x) for x in input().strip().split()]
	(k, ans) = solve(a, n)
	print(k)
	print(*ans, sep=' ')


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []

def find_mex(arr):
	is_there = [False for i in range(len(arr) + 1)]
	for a in arr:
		is_there[a] = True
	for i in range(len(is_there)):
		if not is_there[i]:
			return i

def is_sorted(arr):
	for i in range(len(arr) - 1):
		if arr[i] > arr[i + 1]:
			return False
	return True
for _ in range(testCases):
	n = int(input())
	arr = input_split()
	rp = n - 1
	ans = []
	while not is_sorted(arr):
		mex = find_mex(arr)
		if mex > rp:
			arr[rp] = mex
			ans.append(rp + 1)
			rp -= 1
		else:
			ans.append(mex + 1)
			arr[mex] = mex
	answers.append(ans)
for ans in answers:
	print(len(ans))
	print(*ans, sep=' ')


import collections as cc
I = lambda : list(map(int, input().split()))

def mex(ar):
	ar = [-1] + sorted(ar)
	for i in range(1, len(ar)):
		if ar[i - 1] != ar[i] and ar[i - 1] + 1 != ar[i]:
			return ar[i - 1] + 1
	return max(ar) + 1

def ch(ar):
	for i in range(len(ar) - 1):
		if l[i] > l[i + 1]:
			return 0
	return 1

def inc(ar):
	for i in range(len(ar)):
		if l[i] != i:
			return i
for tc in range(int(input())):
	(n,) = I()
	l = I()
	ans = []
	while not ch(l):
		me = mex(l)
		ind = inc(l)
		if me == n:
			l[ind] = n
			ans.append(ind + 1)
		else:
			l[me] = me
			ans.append(me + 1)
	print(len(ans))
	print(*ans)


import heapq
from collections import defaultdict

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

def print_list(l):
	print(' '.join(map(str, l)))

def change_mh(n):
	dic[MEX] += 1
	heapq.heappop(mh)
	dic[n] -= 1
	if dic[n] == 0:
		heapq.heappush(mh, n)
N = int(input())
for _ in range(N):
	n = int(input())
	nums = read_list()
	dic = defaultdict(int)
	res = []
	mh = []
	for num in nums:
		dic[num] += 1
	for i in range(n + 1):
		if i not in dic:
			heapq.heappush(mh, i)
	MEX = mh[0]
	while MEX < n:
		res.append(MEX + 1)
		tmp = nums[MEX]
		change_mh(tmp)
		nums[MEX] = MEX
		MEX = mh[0]
	flag = True
	while flag:
		flag = False
		for i in range(n):
			if nums[i] != i:
				res.append(i + 1)
				(nums[i], MEX) = (MEX, nums[i])
				while MEX < n:
					res.append(MEX + 1)
					(nums[MEX], MEX) = (MEX, nums[MEX])
				flag = True
				break
	print(len(res))
	print_list(res)


from collections import Counter, defaultdict as dft
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	dct = Counter(arr)
	mex = 0
	case = 0
	for x in range(n):
		if arr[x] != x:
			ind = x
			case = 1
			break
	if case == 0:
		print(0)
		continue
	res = []
	while mex in dct:
		mex += 1
	if mex == n:
		for x in range(n):
			if arr[x] != x:
				ind = x
				break
	else:
		ind = mex
	for i in range(2 * n):
		res.append(ind + 1)
		temp = arr[ind]
		arr[ind] = mex
		dct[mex] += 1
		dct[temp] -= 1
		if dct[temp] == 0:
			del dct[temp]
		mex = 0
		while mex in dct:
			mex += 1
		if mex == n:
			case = 0
			for x in range(n):
				if arr[x] != x:
					ind = x
					case = 1
					break
			if case == 0:
				break
		else:
			ind = mex
	print(len(res))
	print(*res)


import io
import os
import sys
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

def rint():
	return map(int, input().split())

def oint():
	return int(input())

def get_mex():
	for i in range(n + 1):
		if i not in vs:
			return i
	return -1

def check_valid():
	for i in range(n - 1):
		if a[i] <= a[i + 1]:
			continue
		else:
			return 0
	return 1

def find_oo():
	for i in range(n):
		if a[i] != i:
			return i

def insert_mex(mex):
	if mex == n:
		i = find_oo()
	else:
		i = mex
	cnt[a[i]] -= 1
	if cnt[a[i]] == 0:
		vs.remove(a[i])
	a[i] = mex
	vs.add(mex)
	cnt[mex] += 1
	op.append(i + 1)
	return
t = oint()
for _ in range(t):
	n = oint()
	a = list(rint())
	cnt = [0] * (n + 1)
	vs = set(a)
	for i in range(n):
		cnt[a[i]] += 1
	op = []
	for i in range(n * 2):
		if check_valid():
			break
		mex = get_mex()
		insert_mex(mex)
	print(len(op))
	print(*op)


import heapq
import collections
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = []
	counts = collections.Counter(arr)
	mexs = []
	for i in range(n + 1):
		if i not in counts:
			heapq.heappush(mexs, i)
	while 1:
		mex = heapq.heappop(mexs)
		if mex == n:
			break
		else:
			counts[arr[mex]] -= 1
			if counts[arr[mex]] == 0:
				heapq.heappush(mexs, arr[mex])
			arr[mex] = mex
			ans.append(mex + 1)
	mex = n
	pos = [0] * (n + 1)
	for i in range(n):
		pos[arr[i]] = i
	persuit = 0
	cnt = 0
	while persuit != n:
		if mex == n:
			if pos[persuit] == persuit:
				persuit += 1
			else:
				arr[pos[persuit]] = mex
				mex = persuit
				ans.append(pos[persuit] + 1)
		else:
			tmp = arr[mex]
			arr[mex] = mex
			pos[mex] = mex
			ans.append(mex + 1)
			mex = tmp
	print(len(ans))
	print(*ans)


def mex(ls, v):
	for i in range(v + 1):
		if i not in ls:
			return i
t = int(input())
for i in range(t):
	n = int(input())
	li = list(map(int, input().split()))
	k = 0
	lf = []
	while True:
		a = mex(li, n)
		if a == n:
			li.pop()
			li.insert(n - 1, n)
			k += 1
			lf += [n]
			continue
		elif a < n - 1:
			li.pop(a)
			li.insert(a, a)
			k += 1
			lf += [a + 1]
			continue
		for j in range(n):
			if li[j] != j:
				if j in li:
					c = li.index(j)
					li.pop(c)
					li.insert(c, a)
					k += 1
					lf += [c + 1]
					break
				else:
					li.pop(j)
					li.insert(j, a)
					k += 1
					lf += [j + 1]
					break
		else:
			break
		if j == n - 1:
			break
	print(k)
	lf = list(map(str, lf))
	print(' '.join(lf))


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
sys.setrecursionlimit(10 ** 2)

def print_case_iterable(case_num, iterable):
	print('Case #{}: {}'.format(case_num, ' '.join(map(str, iterable))))

def print_case_number(case_num, iterable):
	print('Case #{}: {}'.format(case_num, iterable))

def print_iterable(A):
	print(' '.join(A))

def read_int():
	return int(f.readline().strip())

def read_int_array():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def read_string():
	return list(f.readline().strip())

def ri():
	return int(f.readline().strip())

def ria():
	return [int(x) for x in f.readline().strip().split(' ')]

def rns():
	a = [x for x in f.readline().split(' ')]
	return (int(a[0]), a[1].strip())

def rs():
	return list(f.readline().strip())

def bi(x):
	return bin(x)[2:]
from collections import deque
import math
NUMBER = 10 ** 9 + 7

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	return f

def mult(a, b):
	return a * b % NUMBER

def minus(a, b):
	return (a - b) % NUMBER

def plus(a, b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		(g, y, x) = egcd(b % a, a)
		return (g, x - b // a * y, y)

def modinv(a):
	m = NUMBER
	(g, x, y) = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m

def choose(n, k):
	if n < k:
		assert false
	return mult(factorial(n), modinv(mult(factorial(k), factorial(n - k)))) % NUMBER
from collections import deque, defaultdict
import heapq
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def dfs(g, timeIn, timeOut, depths, parents):
	cnt = 0
	stack = [[1, 0, 0, 0]]
	while stack:
		(v, neig_i, parent, depth) = stack[-1]
		parents[v] = parent
		depths[v] = depth
		if neig_i == 0:
			timeIn[v] = cnt
			cnt += 1
		while neig_i < len(g[v]):
			u = g[v][neig_i]
			if u == parent:
				neig_i += 1
				continue
			stack[-1][1] = neig_i + 1
			stack.append([u, 0, v, depth + 1])
			break
		if neig_i == len(g[v]):
			stack.pop()
			timeOut[v] = cnt
			cnt += 1
cnt = 0

@bootstrap
def dfs(v, adj, timeIn, timeOut, depths, parents, parent=0, depth=0):
	global cnt
	parents[v] = parent
	depths[v] = depth
	timeIn[v] = cnt
	cnt += 1
	for u in adj[v]:
		if u == parent:
			continue
		yield dfs(u, adj, timeIn, timeOut, depths, parents, v, depth + 1)
	timeOut[v] = cnt
	cnt += 1
	yield

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)

def get_num_2_5(n):
	twos = 0
	fives = 0
	while n > 0 and n % 2 == 0:
		n //= 2
		twos += 1
	while n > 0 and n % 5 == 0:
		n //= 5
		fives += 1
	return (twos, fives)

def shift(a, i, num):
	for _ in range(num):
		(a[i], a[i + 1], a[i + 2]) = (a[i + 2], a[i], a[i + 1])

def find_mex(a, m):
	b = sorted([x - m for x in a])
	if b[0] > 0:
		return m
	last = 0
	for i in range(len(b)):
		if b[i] > last + 1:
			return last + 1 + m
		last = b[i]
	return b[len(b) - 1] + m + 1

def solution(a, n):
	indexes = []
	mex = find_mex(a, 0)
	while mex < n:
		a[mex] = mex
		indexes.append(mex + 1)
		mex = find_mex(a, 0)
	a = list(reversed(a))
	for i in range(n - 1, -1, -1):
		if a == sorted(a, reverse=True):
			break
		wanted = n - 1 - i
		if a[i] == wanted:
			a.pop()
			continue
		mex = find_mex(a, wanted)
		if mex == wanted:
			indexes.append(n - 1 - i + 1)
			a.pop()
			continue
		while wanted in a:
			wanted_index = a.index(wanted)
			a[wanted_index] = mex
			indexes.append(n - 1 - wanted_index + 1)
			mex = find_mex(a, wanted)
		indexes.append(n - 1 - i + 1)
		a.pop()
	return str(len(indexes)) + '\n' + ' '.join(map(str, indexes))

def main():
	T = 1
	T = ri()
	for i in range(T):
		n = ri()
		a = ria()
		x = solution(a, n)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			(print >> output, str(x))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


it = lambda : list(map(int, input().strip().split()))

def getMex(N, C):
	for i in range(0, N):
		if C[i] == 0:
			return i
	return N

def solve():
	N = int(input())
	A = it()
	C = [0] * N
	for a in A:
		if a < N:
			C[a] += 1
	k = 0
	R = []
	while True:
		mex = getMex(N, C)
		if mex == N:
			break
		k += 1
		R.append(mex)
		if A[mex] < N:
			assert C[A[mex]] > 0
			C[A[mex]] -= 1
		A[mex] = mex
		C[mex] += 1
	for i in range(N):
		if A[i] == i:
			continue
		mex = A[i]
		A[i] = N
		k += 1
		R.append(i)
		while mex != N:
			k += 1
			R.append(mex)
			tmp = A[mex]
			A[mex] = mex
			mex = tmp
	print(k)
	print(' '.join(map(str, [i + 1 for i in R])))
T = int(input())
for _ in range(T):
	solve()


def mex(arr):
	nums = set(arr)
	for i in range(len(arr) + 2):
		if i not in nums:
			return i

def solve(arr):
	ans = []
	j = len(arr) - 1
	for _ in range(2 * len(arr)):
		v = mex(arr)
		if v >= j + 1 and j >= 0:
			arr[j] = v
			ans.append(j)
			j -= 1
		else:
			arr[v] = v
			ans.append(v)
	return ans
for _ in range(int(input())):
	n = int(input())
	(*arr,) = map(int, input().split())
	res = solve(arr)
	print(len(res))
	print(*[v + 1 for v in res])


import sys
input = sys.stdin.readline
for f in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cont = [0] * (n + 1)
	for x in a:
		cont[x] += 1
	hasall = True
	for i in range(n):
		if cont[i] == 0:
			hasall = False
	cor = 0
	er = -1
	k = 0
	sol = []
	while cor < n:
		if hasall:
			hasall = False
			while cor < n and a[cor] == cor:
				cor += 1
			if cor < n:
				tod = cor
				while a[tod] != cor:
					tod += 1
				k += 1
				sol.append(tod + 1)
				cont[cor] = 0
				er = cor
				cont[n] = 1
				a[tod] = n
		elif er >= 0:
			k += 1
			sol.append(er + 1)
			foo = a[er]
			cont[foo] -= 1
			cont[er] = 1
			a[er] = er
			er = -1
		else:
			er = 0
			while cont[er] > 0:
				er += 1
			if er == n:
				hasall = True
	isok = True
	for i in range(n):
		if a[i] != i:
			isok = False
	if not isok:
		print(2 / 0)
	print(k)
	print(*sol)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	alre = [-1] * n
	for i in range(n):
		if n > a[i] and alre[a[i]] == -1:
			alre[a[i]] = i
	res = [-1] * n
	for i in range(n):
		if alre[i] != -1:
			res[alre[i]] = i
	for i in range(n):
		if res[i] == -1 and alre[i] == -1:
			res[i] = i
	mada = []
	check = set(res)
	for i in range(n):
		if i not in check:
			mada.append(i)
	for i in range(n):
		if res[i] == -1:
			res[i] = mada[-1]
			mada.pop()
	ID = {i: e for (e, i) in enumerate(res)}
	for i in range(n):
		if alre[i] == -1:
			ans.append(ID[i])
	gomi = n
	check = [i for i in range(n)]
	while True:
		if gomi == n:
			for i in range(n):
				if res[i] != i:
					(res[i], gomi) = (gomi, res[i])
					ans.append(i)
					break
		else:
			ans.append(gomi)
			(res[gomi], gomi) = (gomi, res[gomi])
		if res == check:
			break
	for i in range(len(ans)):
		ans[i] += 1
	print(len(ans))
	print(*ans)


tct = int(input())
n = 0
t = []

def calc():
	chk = 0
	for i in range(n - 1):
		if t[i] > t[i + 1]:
			chk = 1
	if chk == 0:
		return -69
	ct = []
	for x in range(n + 1):
		ct.append(0)
	for x in t:
		ct[x] += 1
	for x in range(n + 1):
		if ct[x] == 0:
			return x
while tct > 0:
	n = int(input())
	t = [int(x) for x in input().split()]
	x = 1
	opct = 0
	moves = list()
	guard = n
	while x >= 0:
		x = calc()
		if x < 0:
			break
		if x == guard:
			t[x - 1] = x
			guard -= 1
			opct += 1
			moves.append(x)
		else:
			t[x] = x
			opct += 1
			moves.append(x + 1)
	print(opct)
	for x in moves:
		print(x, end=' ')
	print()
	tct -= 1


import heapq
t = int(input())

def get_tex_bool(a):
	tb = [True] * (len(a) + 1)
	for aa in a:
		tb[aa] = False
	ta = []
	for i in range(len(tb)):
		if tb[i] == True:
			ta.append(i)
	return ta
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	ta = get_tex_bool(a)
	heapq.heapify(ta)
	ans = []
	for j in range(len(a)):
		if a[j] == j:
			continue
		else:
			k = j
			while k != n:
				cur = heapq.heappop(ta)
				if a[k] not in a[:k] + a[k + 1:]:
					heapq.heappush(ta, a[k])
				ans.append(k + 1)
				temp = a[k]
				a[k] = cur
				k = temp
	print(len(ans))
	print(' '.join([str(x) for x in ans]))


def mex(chk, n):
	for i in range(n + 1):
		if i not in chk:
			return i
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	w = [i for i in range(n)]
	ans = []
	while arr != w:
		p = mex(arr, n)
		if p == n:
			for j in range(n):
				if arr[j] != j:
					arr[j] = p
					ans.append(j + 1)
					break
		else:
			arr[p] = p
			ans.append(p + 1)
	print(len(ans))
	print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = []
	count = [0] * (n + 1)
	for i in l:
		count[i] += 1
	while True:
		check = True
		for i in range(n):
			if count[i] == 0:
				count[l[i]] -= 1
				count[i] += 1
				ans.append(i + 1)
				l[i] = i
				check = False
				break
		if check:
			for i in range(n - 1, -1, -1):
				if l[i] != i:
					count[n] += 1
					count[l[i]] -= 1
					l[i] = n
					ans.append(i + 1)
					check = False
					break
		if check:
			break
	print(len(ans))
	print(*ans)


from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())

def mex(a):
	m = [0] * (len(a) + 1)
	for i in a:
		m[i] = 1
	for i in range(len(m)):
		if m[i] == 0:
			return i
for _ in range(t):
	n = int(inp())
	a = [int(x) for x in inp().split()]
	aFinal = list(range(n))
	ans = []
	h = n - 1
	while True:
		if a == aFinal:
			break
		x = mex(a)
		if x > n - 1:
			while True:
				if a[h] == aFinal[h]:
					h -= 1
				else:
					break
			a[h] = x
			ans.append(h + 1)
			h -= 1
		else:
			a[x] = x
			ans.append(x + 1)
	print(len(ans))
	print(*ans)


o = int(input())
for _ in range(o):
	n = int(input())
	A = list(map(int, input().split(' ')))
	dic = {}
	for i in range(n + 2):
		dic[i] = 0
	for i in A:
		if i in dic:
			dic[i] += 1

	def Find(x):
		for i in range(x + 1, n + 2):
			if dic[i] == 0:
				return i

	def CHECK():
		done = False
		for i in range(1, n):
			if A[i] < A[i - 1]:
				return done
		return True
	ans = []
	i = 0
	result = False
	while i < n:
		if result:
			break
		if A[i] == i:
			i += 1
			continue
		mex = Find(i - 1)
		if mex < n and A[mex] != mex:
			dic[mex] += 1
			dic[A[mex]] -= 1
			A[mex] = mex
			ans.append(mex)
			result = CHECK()
		else:
			for j in range(i + 1, n):
				if A[j] == i:
					temp = mex
					dic[A[j]] -= 1
					A[j] = temp
					dic[temp] += 1
					ans.append(j)
					result = CHECK()
					break
	print(len(ans))
	for i in ans:
		print(i + 1, end=' ')


import heapq

def solve(arr):
	n = len(arr)
	moves = []
	j = 0
	counter = [0 for _ in range(n + 1)]
	for num in arr:
		counter[num] += 1
	h = []
	for i in range(n + 1):
		if counter[i] == 0:
			heapq.heappush(h, i)
	while j < n:
		minimal = heapq.heappop(h)
		if minimal < n:
			counter[arr[minimal]] -= 1
			if counter[arr[minimal]] == 0:
				heapq.heappush(h, arr[minimal])
			arr[minimal] = minimal
			counter[minimal] += 1
			moves.append(minimal + 1)
		elif arr[j] == j:
			heapq.heappush(h, n)
			j += 1
		else:
			counter[arr[j]] -= 1
			if counter[arr[j]] == 0:
				heapq.heappush(h, arr[j])
			arr[j] = n
			counter[n] += 1
			moves.append(j + 1)
	return moves
T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	moves = solve(arr)
	print(len(moves))
	print(' '.join(map(str, moves)))


tt = int(input())
for loop in range(tt):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	mexlis = [-1] * (n + 1)
	for i in range(n):
		if a[i] <= n + 1:
			mexlis[a[i]] = 0
	cnt = 0
	while True:
		for i in range(n + 1):
			if mexlis[i] != cnt:
				mex = i
				break
		if mex == n:
			for i in range(n):
				if a[i] != i:
					ans.append(i + 1)
					a[i] = mex
					break
			else:
				break
		else:
			ans.append(mex + 1)
			a[mex] = mex
		cnt += 1
		for i in range(n):
			mexlis[a[i]] = cnt
	print(len(ans))
	print(*ans)


t = int(input())
for _ in range(0, t):
	n = int(input())
	aa = [int(i) for i in input().split()]
	ss = 0
	for i in range(0, n):
		if i != aa[i]:
			ss += 1
	ans = []
	while ss != 0:
		se = set(aa)
		mex = -1
		for i in range(0, n + 1):
			if i not in se:
				mex = i
				break
		if mex == n:
			for i in range(0, n):
				if i != aa[i]:
					aa[i] = mex
					ans.append(i + 1)
					break
		else:
			aa[mex] = mex
			ss -= 1
			ans.append(mex + 1)
	print(len(ans))
	print(*ans)


import sys
input = sys.stdin.readline

def check(ar, n):
	flag = False
	for i in range(1, n):
		if ar[i] < ar[i - 1]:
			flag = True
			break
	return flag
for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	fin = 0
	ans = []
	while check(ar, n):
		se = set(ar)
		me = n
		for i in range(n):
			if not i in se:
				me = i
				break
		if me == n:
			for i in range(n):
				if ar[i] != i:
					fin += 1
					ans.append(i + 1)
					ar[i] = n
					break
		else:
			fin += 1
			ans.append(i + 1)
			ar[i] = i
	print(fin)
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	li = [0] * n
	ans = []
	indexcount = n
	sortar = ar[:]
	sortar.sort()
	if sortar == ar:
		print(0)
		print()
	else:

		def mex(ar):
			s = set(ar)
			n = 0
			while n in s:
				n += 1
			return n

		def unfixed(li):
			for i in range(len(li)):
				if li[i] == 0:
					return i
		while indexcount > 0:
			varmex = mex(ar)
			indpos = varmex % n
			if varmex == n:
				point = unfixed(li)
				ar[point] = varmex
				ans.append(point + 1)
			else:
				ar[indpos] = varmex
				li[indpos] = 1
				ans.append(indpos + 1)
				indexcount -= 1
		print(len(ans))
		print(*ans)


t = int(input())
for x in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in range(n + 1):
		d[i] = 0
	for i in l:
		d[i] += 1
	ff = 0
	fl = []
	while True:
		ff += 1
		for j in d.keys():
			if d[j] == 0:
				m = j
				break
		p = m - 1
		if m == 0:
			c = 0
			for j in range(n):
				if l[j] != j + 1:
					p = j
					c = 1
					break
			if c == 0:
				break
		d[l[p]] -= 1
		l[p] = m
		fl.append(p + 1)
		d[m] += 1
	print(ff - 1)
	for i in fl:
		print(i, end=' ')
	print()


from collections import Counter
import sys
input = sys.stdin.readline
T = int(input())
for t in range(T):
	N = int(input())
	A = [int(_) for _ in input().split()]
	inds = []
	cc = Counter(A)
	noq = set()
	for (i, el) in enumerate(A):
		if i != el:
			noq.add(i)
	current_min = 0
	while noq:
		while cc[current_min]:
			current_min += 1
		if current_min == N:
			choice = next(iter(noq))
		else:
			choice = current_min
			if choice in noq:
				noq.remove(choice)
		replaced_el = A[choice]
		A[choice] = current_min
		cc[replaced_el] -= 1
		cc[current_min] += 1
		if cc[replaced_el] == 0:
			if replaced_el < current_min:
				current_min = replaced_el
		inds.append(choice + 1)
	print(len(inds))
	print(' '.join(map(str, inds)))


import sys
input = sys.stdin.readline
from collections import defaultdict as dd, deque as dq
t = int(input())
while t:
	n = int(input())
	lol = 0
	d = dd(dq)
	l = list(map(int, input().split()))
	res = []
	for i in range(n):
		d[l[i]].append(i)
	while 1:
		m = 0
		ll = sorted(l)
		for j in range(n):
			if ll[j] == m:
				m += 1
			elif ll[j] > m:
				break
		if m == n:
			break
		l[m] = m
		res.append(m + 1)
		i += 1
	t -= 1
	cycle = []
	vis = [0] * n
	for i in range(n):
		if vis[i] == 0:
			vis[i] = 1
			next = l[i]
			ll = [i]
			while next != i:
				vis[next] = 1
				ll.append(next)
				next = l[next]
			cycle.append(ll)
	for i in cycle:
		if len(i) > 1:
			for j in i:
				res.append(j + 1)
			res.append(i[0] + 1)
	print(len(res))
	print(*res)


from sys import stdin, gettrace, stderr
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def solve():
	n = int(inputi())
	aa = [int(a) for a in inputi().split()]
	counts = [0] * (n + 1)
	for a in aa:
		counts[a] += 1
	res = []
	loop(aa, counts, n, res)
	print(len(res))
	print(' '.join(map(str, res)))

def loop(aa, counts, n, res):
	while True:
		mex = counts.index(0)
		if mex == n:
			i = 0
			for i in range(n):
				if aa[i] < i:
					break
			else:
				return
			counts[aa[i]] -= 1
			aa[i] = mex
			counts[n] = 1
			res.append(i + 1)
		else:
			counts[mex] += 1
			counts[aa[mex]] -= 1
			aa[mex] = mex
			res.append(mex + 1)

def main():
	t = int(inputi())
	for _ in range(t):
		solve()
main()


def MEX(b):
	for i in range(len(b) + 1):
		if i in b:
			continue
		else:
			return i

def index(b):
	i = 0
	for j in range(len(b)):
		if b[j] != j:
			return j
	return len(b) - 1
t = int(input())
answer = []
for kek in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	y = 0
	flag = True
	kekes = 2 * n
	while kekes > 0 and flag:
		kekes -= 1
		x = MEX(a)
		if x >= n:
			y = index(a)
			a[y] = x
			ans.append(y + 1)
		else:
			ans.append(x + 1)
			a[x] = x
		if len(ans) >= 4:
			if ans[-1] == ans[-2] and ans[-2] == ans[-3] and (ans[-3] == ans[-4]) and (ans[-1] == n):
				flag = False
	print(len(ans))
	print(*ans)


import heapq as h
T = int(input())
while T:
	n = int(input())
	A = list(map(int, input().split()))
	C = [0 for i in range(n + 1)]
	Z = []
	for i in A:
		C[i] += 1
	H = []
	for i in range(n + 1):
		if C[i] == 0:
			H.append(i)
	h.heapify(H)
	F = True
	p = 0
	while F and p < 2 * n:
		c = 0
		p = p + 1
		for i in range(n - 1):
			if A[i] > A[i + 1]:
				c = 1
		if c == 0:
			F = False
			break
		else:
			x = h.heappop(H)
			j = 0
			for i in range(n):
				if A[i] != i:
					j = i
			if x != n:
				j = x
			C[A[j]] = C[A[j]] - 1
			if C[A[j]] == 0:
				h.heappush(H, A[j])
			A[j] = x
			C[x] = C[x] + 1
			Z.append(j + 1)
	print(len(Z))
	print(*Z)
	T = T - 1


def sor(A):
	for i in range(1, n):
		if A[i] < A[i - 1]:
			return False
	return True
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	cnt = [0 for i in range(n + 1)]
	for i in A:
		cnt[i] += 1
	Ans = []
	r = n - 1
	x = 0
	while not sor(A):
		x = 0
		while cnt[x] != 0:
			x += 1
		if x > r:
			cnt[A[r]] -= 1
			cnt[x] += 1
			A[r] = x
			Ans.append(r + 1)
			r -= 1
			continue
		Ans.append(x + 1)
		cnt[A[x]] -= 1
		cnt[x] += 1
		A[x] = x
	print(len(Ans))
	print(*Ans)


from math import gcd

def get_mex(a):
	for i in range(len(a)):
		if a[i] == 0:
			return i

def f(a):
	cnt = [0] * (len(a) + 1)
	for i in a:
		cnt[i] += 1
	ans = []
	mex = get_mex(cnt)
	ll = 0
	while a != sorted(a):
		if mex < len(a):
			cnt[a[mex]] -= 1
			cnt[mex] += 1
			a[mex] = mex
			ans.append(mex + 1)
			mex = get_mex(cnt)
		else:
			for i in range(len(a)):
				if a[i] != i:
					cnt[a[i]] -= 1
					cnt[mex] += 1
					a[i] = mex
					ans.append(i + 1)
					break
			mex = get_mex(cnt)
	print(len(ans))
	return ans
for i in range(int(input())):
	a = input().strip()
	lst = list(map(int, input().strip().split()))
	print(*f(lst))


import heapq as hq
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	dic = {}
	mex = []
	miss = 0
	ans = []
	rem = []
	arr1 = arr[:]
	for i in range(n + 1):
		dic[i] = 0
	for i in arr:
		dic[i] += 1
	for i in range(n + 1):
		if dic[i] == 0:
			hq.heappush(mex, i)
	for i in range(n):
		if arr[i] != i:
			miss += 1
			rem.append(i)
	while miss > 0:
		m = hq.heappop(mex)
		if m == n:
			r = rem[-1]
			dic[arr[r]] -= 1
			if dic[arr[r]] == 0:
				hq.heappush(mex, arr[r])
			arr[r] = m
			ans.append(r)
			dic[m] += 1
		else:
			dic[arr[m]] -= 1
			if dic[arr[m]] == 0:
				hq.heappush(mex, arr[m])
			arr[m] = m
			ans.append(m)
			rem.remove(m)
			dic[m] += 1
			miss -= 1
	print(len(ans))
	for i in ans:
		print(i + 1, end=' ')
	print()


T = int(input())
from collections import Counter
for _ in range(T):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	for i in range(2 * n):
		b = Counter(a)
		fl = False
		for j in range(n):
			mex = n
			if b[j] == 0:
				mex = j
				break
		if mex == n:
			for j in range(n):
				if j != a[j]:
					a[j] = n
					ans.append(j + 1)
					break
		else:
			a[mex] = mex
			ans.append(mex + 1)
	print(len(ans))
	print(*ans)


t = int(input())
for ii in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	numUnfixed = 0
	for i in range(n):
		if i != a[i]:
			numUnfixed += 1
	ans = []
	while numUnfixed != 0:
		s = set(a)
		for i in range(n + 1):
			if i not in s:
				mex = i
				break
		if mex != n:
			a[mex] = mex
			numUnfixed -= 1
			ans.append(mex + 1)
		else:
			for i in range(n):
				if i != a[i]:
					a[i] = mex
					ans.append(i + 1)
					break
	print(len(ans))
	print(*ans)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def solve(n, a):
	res = []
	while n > 0:
		s = set(a[:n])
		mex = 0
		while mex < n and mex in s:
			mex += 1
		if mex == n:
			a[n - 1] = mex
			res.append(n)
			n -= 1
		else:
			res.append(mex + 1)
			a[mex] = mex
	wi(len(res))
	wia(res)

def main():
	for _ in range(ri()):
		n = ri()
		a = ria()
		solve(n, a)
main()


from sys import stdin, stdout, setrecursionlimit
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log, log2
from random import seed, randint
from datetime import datetime
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
from collections import defaultdict as dd
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def def_value():
	return 0

def def_inf():
	return inf

def mex(a, n):
	x = set(a)
	for i in range(n + 1):
		if i not in x:
			return i
for _ in range(iinp()):
	n = iinp()
	a = lmp()
	ans = []
	while a != sorted(a):
		x = mex(a, n)
		if x == n:
			for i in range(n):
				if a[i] != i:
					a[i] = x
					ans.append(i + 1)
					break
		else:
			a[x] = x
			ans.append(x + 1)
	print(len(ans))
	print(*ans)


import sys
import heapq, functools, collections
import math, random
from collections import Counter, defaultdict

def solve(lst):
	console('----- solving ------')
	console(lst)
	res = []
	nums = set(range(len(lst) + 1))
	console('nums', nums)
	for i in range(len(lst)):
		mex = min(nums - set(lst))
		console('mex', mex)
		if mex == len(lst):
			break
		res.append(mex)
		lst[mex] = mex
		console('lst', lst)
	d = {}
	for (i, x) in enumerate(lst):
		d[x] = i
	console(d)
	for i in range(len(lst)):
		if i == lst[i]:
			continue
		start = i
		current = i
		next_node = lst[i]
		res.append(start)
		console('starting', i, lst[i])
		while next_node != start:
			current = next_node
			next_node = lst[current]
			lst[current] = current
			console(current, next_node, lst)
			res.append(current)
		res.append(start)
	console(res)
	return ' '.join([str(x + 1) for x in res])

def console(*args):
	return
cases = int(input())
inn = sys.stdin.readlines()
for case_num in range(cases):
	lst = list(map(int, inn[2 * case_num + 1].split()))
	res = solve([x for x in lst])
	print(len(res.split()))
	print(res)


def mex(a, n):
	mylist = [True] * (n + 1)
	for x in range(n):
		mylist[a[x]] = False
	for x in range(n + 1):
		if mylist[x]:
			return x
from sys import stdin, stdout
for query in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = [int(x) for x in stdin.readline().split()]
	output = []
	while a != list(range(n)):
		y = mex(a, n)
		if y == n:
			for z in range(n):
				if a[z] != z:
					output.append(z + 1)
					a[z] = y
					break
		else:
			output.append(y + 1)
			a[y] = y
	stdout.write(str(len(output)) + '\n')
	for x in output:
		stdout.write(str(x) + ' ')
	stdout.write('\n')


import sys, math, random
input = sys.stdin.readline

def fmx(B):
	mex = len(B) - 1
	for i in range(len(B)):
		if B[i] == 0:
			mex = i
			break
	return mex
T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	B = [0 for i in range(N + 1)]
	for i in A:
		B[i] = B[i] + 1
	C = [i for i in range(N)]
	mex = fmx(B)
	K = []
	while A != C:
		if mex == N:
			for i in range(N):
				if A[i] != C[i]:
					B[A[i]] = B[A[i]] - 1
					mex = A[i]
					B[mex] += 1
					A[i] = N
					K.append(i + 1)
					break
		else:
			B[A[mex]] -= 1
			A[mex] = mex
			K.append(mex + 1)
			B[mex] += 1
			mex = fmx(B)
	print(len(K))
	print(*K)


from sys import stdin
input = lambda : stdin.readline().rstrip('\r\n')
from collections import deque as que
from collections import defaultdict as vector
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))

def MEX(ar):
	set_ = set(ar)
	for i in range(2000):
		if i not in set_:
			return i
Testcase = inin()
for _ in range(Testcase):
	n = inin()
	a = inar()
	ans = []
	while True:
		m = MEX(a)
		if m < n:
			a[m] = m
			ans.append(m + 1)
		else:
			for i in range(n):
				if a[i] != i:
					a[i] = m
					ans.append(i + 1)
					break
			else:
				break
	print(len(ans))
	print(*ans)


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop, heapify
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

def st():
	return input().rstrip('\n')

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]

def givemex(l):
	mi = 0
	d = {}
	for i in l:
		d[i] = 1
		while mi in d:
			mi += 1
	return mi
for _ in range(val()):
	n = val()
	l = li()
	l1 = []
	temp = givemex(l)
	while sorted(l) != l:
		if temp == n:
			for i in range(n):
				if l[i] != i:
					l[i] = temp
					l1.append(i + 1)
					break
		else:
			l[temp] = temp
			l1.append(temp + 1)
		temp = givemex(l)
	print(len(l1))
	print(*l1)


import heapq
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	b = [0] * (n + 1)
	q = []
	optim = []
	for i in range(n):
		b[a[i]] += 1
		if a[i] != i:
			optim.append(i)
	for i in range(n + 1):
		if b[i] == 0:
			q.append(i)
	heapq.heapify(q)
	ans = []
	cnt = 0
	while True:
		if len(optim) == 0:
			break
		cnt += 1
		temp1 = heapq.heappop(q)
		if temp1 == n:
			temp3 = optim[0]
			temp2 = a[temp3]
			b[temp2] -= 1
			a[temp3] = temp1
			heapq.heappush(q, temp2)
			ans.append(temp3 + 1)
		else:
			temp2 = a[temp1]
			b[temp2] -= 1
			if b[temp2] == 0 or len(q) == 0:
				heapq.heappush(q, temp2)
			a[temp1] = temp1
			ans.append(temp1 + 1)
			optim.remove(temp1)
	print(cnt)
	print(' '.join((str(n) for n in ans)))


def modinv(n, p):
	return pow(n, p - 2, p)
from collections import Counter

def main():
	for case in range(int(input())):
		moves = []
		n = int(input())
		arr = [int(x) for x in input().split()]
		ct = Counter(arr)
		for i in range(2 * n):
			for j in range(0, n + 1):
				if j != n and ct[j] == 0:
					moves.append(j + 1)
					ct[j] += 1
					ct[arr[j]] -= 1
					arr[j] = j
					break
				elif j == n and ct[j] == 0:
					k = 0
					for k in range(n):
						if arr[k] != k:
							break
					moves.append(k + 1)
					ct[n] += 1
					ct[arr[k]] -= 1
					arr[k] = n
		print(len(moves))
		print(*moves)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def MEX(b):
	for i in range(max(b) + 2):
		if i not in b:
			return i
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	arr = []
	while 1:
		x = sorted(a)
		if x == a:
			break
		m = MEX(a)
		if m == max(a) + 1:
			for i in range(n):
				if a[i] != i:
					a[i] = m
					arr.append(i + 1)
					break
		else:
			a[m] = m
			arr.append(m + 1)
		ans += 1
	print(ans)
	print(*arr, sep=' ')


from sys import stdin
input = stdin.readline

def so(l):
	k = len(l)
	for i in range(1, k):
		if l[i] < l[i - 1]:
			return False
	return True
q = int(input())
for _ in range(q):
	n = int(input())
	l = list(map(int, input().split()))
	zaj = [0] * (n + 1)
	odp = []
	for i in l:
		zaj[i] += 1
	cur = 0
	while True:
		if so(l):
			print(len(odp))
			for i in range(len(odp)):
				odp[i] += 1
			print(*odp)
			break
		for i in range(n + 1):
			if zaj[i] == 0:
				mex = i
				break
		if mex < n:
			odp.append(mex)
			if l[mex] <= n:
				zaj[l[mex]] -= 1
			zaj[mex] += 1
			l[mex] = mex
		else:
			while True:
				if cur >= n:
					break
				if l[cur] == cur:
					cur += 1
				else:
					break
			for i in range(n):
				if l[i] == cur:
					dopop = i
					break
			l[dopop] = cur + 10000000
			zaj[l[cur]] -= 1
			l[cur] = cur
			odp.append(dopop)
			odp.append(cur)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	out = []
	done = False
	while not done:
		seen = [False] * (n + 1)
		loc = [-1] * (n + 1)
		for i in range(n):
			v = l[i]
			loc[v] = i
			seen[v] = True
		fix = False
		for m in range(n):
			if not seen[m]:
				fix = True
				break
		if fix:
			out.append(m + 1)
			l[m] = m
		else:
			for i in range(n - 1):
				if l[i] != i:
					j = loc[i]
					out.append(j + 1)
					l[j] = n
					break
			else:
				done = True
	print(len(out))
	print(' '.join(map(str, out)))


from collections import Counter
from heapq import heappush, heappop
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	cnts = Counter(a)
	MEX = []
	for i in range(n + 1):
		if i not in cnts:
			heappush(MEX, i)
	while True:
		curr_MEX = heappop(MEX)
		if curr_MEX == n:
			break
		else:
			cnts[a[curr_MEX]] -= 1
			if cnts[a[curr_MEX]] == 0:
				heappush(MEX, a[curr_MEX])
			a[curr_MEX] = curr_MEX
			ans.append(curr_MEX + 1)
	pos = [0] * (n + 1)
	curr_MEX = n
	for i in range(n):
		pos[a[i]] = i
	persuit = 0
	while persuit != n:
		if curr_MEX == n:
			if pos[persuit] == persuit:
				persuit += 1
			else:
				a[pos[persuit]] = curr_MEX
				curr_MEX = persuit
				ans.append(pos[persuit] + 1)
		else:
			temp = a[curr_MEX]
			a[curr_MEX] = curr_MEX
			pos[curr_MEX] = curr_MEX
			ans.append(curr_MEX + 1)
			curr_MEX = temp
	print(len(ans))
	print(*ans)


def mex(a):
	b = list(set(a))
	x = len(b)
	b.sort()
	f = False
	for i in range(x):
		if b[i] != i:
			return i
			f = True
			break
	if f == False:
		return x
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = sorted(a)
	if a == b:
		print(0)
	else:
		c = [i for i in range(n)]
		x = mex(a)
		b = []
		i = 0
		while True:
			if a == c:
				break
			elif x == n:
				for j in range(n):
					if a[j] != j:
						a[j] = x
						b.append(j + 1)
						x = mex(a)
						break
			else:
				a[x] = x
				b.append(x + 1)
				x = mex(a)
		print(len(b))
		print(*b)


def check_valid(a):
	l = len(a)
	for i in range(1, l):
		if a[i] < a[i - 1]:
			return False
	return True

def find_mex(a):
	s = sorted(a)
	l = len(s)
	mex = 0
	if s[0] != 0:
		return 0
	for i in range(1, l):
		if s[i] - s[i - 1] > 1:
			return s[i - 1] + 1
	return s[l - 1] + 1
t = int(input())
for tt in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	mmax = max(a)
	k = 0
	ans_list = []
	while k <= n * 2:
		if check_valid(a):
			break
		k = k + 1
		mex = find_mex(a)
		if mex == n:
			for i in range(n):
				if a[i] != i:
					a[i] = mex
					ans_list.append(i + 1)
					break
		else:
			a[mex] = mex
			ans_list.append(mex + 1)
	print(k)
	print(*ans_list, sep=' ')


def mex(x):
	i = 0
	for j in set(sorted(x)):
		if j != i:
			return i
		else:
			i += 1
	return i
for _ in range(int(input())):
	n = int(input())
	a = [*map(int, input().split())]
	ans = []
	while sorted(a) != a:
		m = mex(a)
		if m == n:
			for i in range(n):
				if a[i] != i:
					ans.append(i + 1)
					a[i] = m
					break
			m = mex(a)
		a[m] = m
		ans.append(m + 1)
	print(len(ans))
	print(*ans)


def Mex(lst):
	mex = 0
	while mex in lst:
		mex += 1
	return mex
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	count = 0
	while a != list(range(n)):
		mex = Mex(a)
		count += 1
		if mex < n:
			a[mex] = mex
			ans.append(mex + 1)
		else:
			for i in range(n):
				if a[i] != i:
					a[i] = mex
					ans.append(i + 1)
					break
	print(count)
	print(*ans)


production = True
import sys, math, collections

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()[:-1]
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = list(next_line)
		elif input_format == 4:
			formatted_input = list(map(int, list(next_line)))
		elif input_format == 5:
			formatted_input = next_line.split()
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 2:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enu = enumerate
ter = lambda a, b, c: b if a else c

def mapl(iterable, format=0):
	if format == 0:
		return list(map(int, iterable))
	elif format == 1:
		return list(map(str, iterable))
	elif format == 2:
		return list(map(list, iterable))

def solve():
	n = input(11)
	a = input(1)
	f = [0] * (2 * n)
	for i in a:
		f[i] += 1
	log(a)
	s = [0] * n
	m = []
	done = False
	while not done:
		g = 0
		while f[g]:
			g += 1
		if g == n:
			y = 0
			while s[y]:
				y += 1
				if y == n:
					done = True
					break
		else:
			s[g] = 1
			y = g
		if done:
			break
		log(g, y)
		f[a[y]] -= 1
		a[y] = g
		f[g] += 1
		m.append(y + 1)
		log(a)
	out(len(m))
	log(n)
	out(m, 1)
	return
for i in range(input(11)):
	solve()


import sys
import math
import collections
import heapq

def set_debug(debug_mode=False):
	if debug_mode:
		fin = open('input.txt', 'r')
		sys.stdin = fin

def int_input():
	return list(map(int, input().split()))

def mex(d):
	i = 0
	while d[i]:
		i += 1
	return i
t = int(input())
for ti in range(1, t + 1):
	n = int(input())
	a = int_input()
	d = collections.defaultdict(int)
	for x in a:
		d[x] += 1
	res = []
	for i in range(2 * n):
		m = mex(d)
		if m == n:
			for j in range(n):
				if j != a[j]:
					d[a[j]] -= 1
					d[m] += 1
					a[j] = m
					res.append(j + 1)
					break
			else:
				break
		else:
			d[a[m]] -= 1
			d[m] += 1
			a[m] = m
			res.append(m + 1)
	print(len(res))
	print(*res)


from heapq import heappop, heappush, heapify
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	li = [0] * (n + 1)
	for i in a:
		li[i] += 1
	mexs = list(set(range(n + 1)) - set(a))
	heapify(mexs)
	ans = []
	while True:
		nxt = heappop(mexs)
		if nxt < n:
			ans.append(nxt + 1)
			li[a[nxt]] -= 1
			if li[a[nxt]] == 0:
				heappush(mexs, a[nxt])
			a[nxt] = nxt
			li[nxt] = 1
		else:
			for i in range(n):
				if a[i] != i:
					ans.append(i + 1)
					li[a[i]] -= 1
					if li[a[i]] == 0:
						heappush(mexs, a[i])
					a[i] = n
					li[n] = 1
					break
			else:
				break
	print(len(ans))
	print(*ans)


import heapq
for _ in range(int(input())):
	n = int(input())
	s = list(map(int, input().split()))
	exist = [0] * (n + 1)
	unfit = set()
	for (i, x) in enumerate(s):
		exist[x] += 1
		if i != x:
			unfit.add(i)
	h = []
	for (i, x) in enumerate(exist):
		if x == 0:
			heapq.heappush(h, i)
	ans = []
	while len(unfit) != 0:
		MIN = heapq.heappop(h)
		if MIN == n:
			place = unfit.pop()
			ans.append(place + 1)
			kick = s[place]
			s[place] = n
			unfit.add(place)
			heapq.heappush(h, kick)
			exist[kick] -= 1
			exist[n] += 1
		else:
			ans.append(MIN + 1)
			unfit.remove(MIN)
			kick = s[MIN]
			s[MIN] = MIN
			exist[kick] -= 1
			if exist[kick] == 0:
				heapq.heappush(h, kick)
			exist[MIN] += 1
	print(len(ans))
	print(*ans)


import sys
import math
import heapq
import collections

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	n = inputnum()
	a = inputlist()
	ans = []
	while 1 == 1:
		has = [0] * (n + 1)
		for c in a:
			has[c] = 1
		mex = 0
		while has[mex]:
			mex += 1
		if mex == n:
			x = 0
			while x < n and x == a[x]:
				x += 1
			if x == n:
				break
			ans.append(x + 1)
			a[x] = mex
		else:
			ans.append(mex + 1)
			a[mex] = mex
	print(len(ans))
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = []
	k = 0
	while k <= 2 * n:
		am = True
		for i in range(1, n):
			if a[i] < a[i - 1]:
				am = False
				break
		if am:
			break
		mex = n
		arr = [0 for _ in range(n + 1)]
		for i in range(n):
			arr[a[i]] = 1
		for i in range(n + 1):
			if arr[i] == 0:
				mex = i
				break
		if mex == n:
			j = 0
			while j < n:
				if a[j] != j:
					a[j] = n
					l.append(j + 1)
					break
				j += 1
		else:
			a[mex] = mex
			l.append(mex + 1)
		k += 1
	print(len(l))
	print(*l)


t = int(input())
from collections import defaultdict

def find():
	global n
	for i in range(n + 1):
		if i not in l:
			return i

def fn():
	global n
	for i in range(n):
		if l[i] != i:
			return i

def f():
	global a
	for j in range(n):
		d[l[j]] = j
	l1.append(d[0] + 1)
	l[d[0]] = n
	while l != sorted(l):
		a = find()
		if a == n:
			b = fn()
			l1.append(d[b] + 1)
			l[d[b]] = n
			a = find()
		l1.append(a + 1)
		l[a] = a
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = 0
	d = defaultdict(int)
	l1 = []
	a = find()
	if a == n:
		f()
	else:
		while a != n:
			l1.append(a + 1)
			l[a] = a
			a = find()
		if l != sorted(l):
			f()
	print(len(l1))
	print(*l1)


import math, sys, bisect
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])
for _ in range(int(input())):
	N = int(input())
	A = alele()
	mark = [0] * (N + 1)
	for i in A:
		mark[i] += 1
	Ans = []
	g = 1
	for _ in range(2 * N):
		for i in range(N + 1):
			if mark[i] == 0:
				mex = i
				break
		if mex == N:
			if A[-1] != mex and A[-1] != mex - 1:
				mark[A[-1]] -= 1
				mark[mex] += 1
				A[-1] = mex
				Ans.append(N)
			else:
				g = 0
				for k in range(N - 1):
					if A[k] != k:
						g = 1
						mark[A[k]] -= 1
						mark[mex] += 1
						A[k] = mex
						Ans.append(k + 1)
						break
				if g == 0:
					break
		else:
			mark[A[mex]] -= 1
			A[mex] = mex
			mark[mex] += 1
			Ans.append(mex + 1)
		if g == 0:
			break
	print(len(Ans))
	print(*Ans)


T = int(input())
for _ in range(T):
	n = int(input())
	ls = list(map(int, input().split()))
	(res, vis) = ([], [0] * n)
	while True:
		for i in range(1, n):
			if ls[i - 1] > ls[i]:
				break
		else:
			break
		(tl, mex) = ([0] * (n + 1), 0)
		for u in ls:
			tl[u] = 1
		for i in range(0, n + 1):
			if not tl[i]:
				mex = i
				break
		p = min(mex, n - 1)
		if vis[p]:
			p = p + 1 if mex > ls[p] else p - 1
		p = max(0, min(p, n - 1))
		res.append(p + 1)
		(ls[p], vis[p]) = (mex, 1)
	print(len(res))
	print(*res)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def mex(li):
	check = [0] * 1001
	for i in li:
		check[i] += 1
	for i in range(len(check)):
		if check[i] == 0:
			return i
from math import *
for _ in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	ans = []
	while 1:
		f = 1
		for i in range(n - 1):
			if li[i] > li[i + 1]:
				f = 0
				break
		if f == 0:
			num = mex(li)
			if num != n:
				ans.append(num + 1)
				li[num] = num
			else:
				for i in range(n):
					if li[i] != i:
						ans.append(i + 1)
						li[i] = n
						break
		else:
			break
	print(len(ans))
	print(*ans)


from math import *
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	l = []
	i = 0
	while i < n:
		if a[i] == i:
			i = i + 1
			continue
		r = set(a)
		s = [i for i in range(n + 1)]
		s1 = set(s)
		s2 = s1.difference(r)
		s2 = list(s2)
		s2.sort()
		mex = s2[0]
		if mex < n:
			a[mex] = mex
			ans = ans + 1
			l.append(mex + 1)
		elif a[i] != i:
			a[i] = mex
			ans = ans + 1
			l.append(i + 1)
		else:
			a[i] = mex
			ans = ans + 1
			l.append(i + 1)
		if a[i] == i:
			i = i + 1
	print(ans)
	print(*l)


from sys import stdin, stdout

def getints():
	return map(int, stdin.readline().strip().split())

def getlist():
	return list(getints())
t = int(stdin.readline().strip())
while t > 0:
	t -= 1
	n = int(stdin.readline().strip())
	a = getlist()
	cnt = []
	for i in range(0, n + 10):
		cnt.append(0)
	ans = []
	for i in a:
		cnt[i] += 1
	while True:
		c = False
		for i in range(0, n):
			if a[i] != i:
				c = True
				break
		if not c:
			break
		for i in range(0, n + 1):
			if cnt[i] == 0:
				mex = i
				break
		if mex == n:
			for i in range(0, n):
				if a[i] != i:
					cnt[a[i]] -= 1
					cnt[mex] += 1
					a[i] = mex
					ans.append(i + 1)
					break
		else:
			cnt[a[mex]] -= 1
			cnt[mex] += 1
			a[mex] = mex
			ans.append(mex + 1)
	print(len(ans))
	for i in ans:
		print(i, end=' ')
	print()


def find_mex(ar):
	n = len(ar)
	allNums = [i for i in range(n + 1)]
	for x in ar:
		allNums[x] = n
	for x in allNums:
		if x != n:
			return x
	return n

def first_problem_index(ar):
	for i in range(len(ar)):
		if i != ar[i]:
			return i
	return -1

def solve():
	n = int(input().strip())
	ar = list(map(int, input().strip().split()))
	operations = []
	fpi = first_problem_index(ar)
	while fpi >= 0:
		mex = find_mex(ar)
		if mex == n:
			ar[fpi] = mex
			operations.append(fpi + 1)
		else:
			ar[mex] = mex
			operations.append(mex + 1)
		fpi = first_problem_index(ar)
	print(len(operations))
	print(*operations)
t = int(input().strip())
for _ in range(t):
	solve()


def mex(arr):
	hashi = dict()
	i = 0
	for i in arr:
		hashi[i] = 1
	i = 0
	while i in hashi:
		i += 1
	return i
t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	fina = []
	change = []
	done = dict()
	for i in range(n):
		if li[i] != i:
			change.append(i)
	while change != []:
		if change[0] in done:
			change.pop(0)
			continue
		z = mex(li)
		if z == n:
			for i in change:
				if li[i] == change[0]:
					fina.append(i)
					li[i] = n
					break
			fina.append(change[0])
			li[change[0]] = change[0]
			change.pop(0)
		else:
			li[z] = z
			fina.append(z)
			done[z] = 1
	print(len(fina))
	for i in fina:
		print(i + 1, end=' ')
	print()


def mex(arr):
	arr1 = set(arr)
	for i in range(n + 1):
		if not i in arr1:
			return i
for w in range(int(input())):
	n = int(input())
	arr = list(map(int, input().strip().split()))
	l = []
	j = 0
	c = 0
	while j < n:
		m = mex(arr)
		if m == n:
			while j < n and arr[j] == j:
				j += 1
			if j < n:
				c += 1
				l.append(j + 1)
				arr[j] = m
		else:
			c += 1
			l.append(m + 1)
			arr[m] = m
	print(c)
	print(*l)


import sys
import math
import itertools
import random
from collections import deque

def check(a):
	sizee = len(a)
	for i in range(sizee - 1):
		if a[i] > a[i + 1]:
			return False
	return True

def mex(a):
	sizee = len(a)
	mark = [False for _ in range(sizee + 5)]
	for i in range(sizee):
		mark[a[i]] = True
	for i in range(sizee + 1):
		if mark[i] == False:
			return i
	return sizee

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	last = n - 1
	while check(a) == False:
		mexx = mex(a)
		if mexx == last + 1:
			ans.append(last)
			a[last] = mexx
			last -= 1
		else:
			ans.append(mexx)
			a[mexx] = mexx
	print(len(ans))
	for i in ans:
		print(str(i + 1), end=' ')
	print()
t = int(input())
while t > 0:
	solve()
	t -= 1


from sys import stdin, stdout

def replace_by_MEX(n, a):
	dic = {}
	s = set()
	res = []
	for i in range(n):
		if a[i] not in dic:
			dic[a[i]] = 1
		else:
			dic[a[i]] += 1
		if a[i] != i:
			s.add(i)
	while len(s) > 0:
		m = MEX(dic)
		idx = -1
		if n == MEX(dic):
			idx = next(iter(s))
		else:
			idx = m
			s.remove(idx)
		res.append(idx + 1)
		dic[a[idx]] -= 1
		a[idx] = m
		dic[m] = 1
	return res

def MEX(dic):
	mex = 0
	while mex in dic and dic[mex] > 0:
		mex += 1
	return mex
t = int(stdin.readline())
for i in range(t):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	res = replace_by_MEX(n, a)
	stdout.write(str(len(res)) + '\n')
	stdout.write(' '.join(map(str, res)) + '\n')


from sys import stdin, stdout
fi = stdin
fo = stdout
n_test = int(fi.readline())

def solve():
	n = int(fi.readline())
	a = [int(v) for v in fi.readline().split()]

	def mex(arr):
		s = set(arr)
		for i in range(len(arr) + 1):
			if i not in s:
				return i

	def non_decs(arr):
		for (a1, a2) in zip(arr[:-1], arr[1:]):
			if a1 > a2:
				return False
		return True

	def filled(arr, v):
		for idx in range(len(arr), v, -1):
			if arr[idx - 1] != idx:
				return False
		return True
	res = []
	while not non_decs(a):
		val = mex(a)
		if filled(a, val):
			pos = val - 1
		else:
			pos = val
		res.append(str(pos + 1))
		a[pos] = val
	print(len(res))
	print(' '.join(res))
for i_test in range(n_test):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = []
	c = [0] * (n + 1)
	for i in range(n):
		c[a[i]] = 1
	d = []
	for i in range(n + 1):
		if c[i] == 0:
			d.append(i)
	d = min(d)
	if a[0] == 0:
		check = True
	else:
		check = False
	while a != sorted(a):
		for i in range(n):
			if d == 0:
				b.append(1)
				check = True
				a[0] = 0
			elif d == n:
				b.append(n)
				a.remove(a[-1])
				n -= 1
			else:
				b.append(d + 1)
				a[d] = d
			c = [0] * (n + 1)
			for i in range(n):
				c[a[i]] = 1
			d = []
			for i in range(n + 1):
				if c[i] == 0:
					d.append(i)
			d = min(d)
	print(len(b))
	for i in b:
		print(i, end=' ')
	print()


def mex(l):
	global s
	s1 = set(l)
	s2 = s - s1
	l2 = list(s2)
	l2.sort()
	return l2[0]
for _ in range(int(input())):
	ans = []
	n = int(input())
	l = [int(x) for x in input().split()]
	c = l.copy()
	c.sort()
	s = set([int(i) for i in range(n + 1)])
	for i in range(2 * n):
		a = mex(l)
		if a >= n:
			for i in range(n):
				if l[i] != i:
					ans.append(i + 1)
					l[i] = a
					break
		else:
			l[a] = a
			ans.append(a + 1)
	print(len(ans))
	print(*ans)


def mex(l):
	i = 0
	while True:
		if i in l:
			i += 1
		else:
			return i

def isok(l):
	for i in range(1, len(l)):
		if l[i] < l[i - 1]:
			return False
	return True
t = int(input())
for i in range(t):
	n = int(input())
	res_list = []
	l = list(map(int, input().split(' ')))
	while not isok(l):
		l_mex = mex(l)
		if l_mex != n:
			l[l_mex] = l_mex
			res_list.append(l_mex + 1)
		else:
			for i in range(len(l)):
				if i != l[i]:
					l[i] = l_mex
					res_list.append(i + 1)
					break
	print(len(res_list))
	print(' '.join(list(map(str, res_list))))


t = int(input())
for i in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	len_ls = len(ls)
	res = []
	proper_place = 0
	for idx in range(len_ls):
		if ls[idx] == idx:
			proper_place += 1
	my_dict = {}
	for item in ls:
		if item in my_dict:
			my_dict[item] += 1
		else:
			my_dict[item] = 1
	count = len_ls - proper_place
	while count != 0:
		change = False
		for idx in range(len_ls):
			if not idx in my_dict:
				res.append(idx + 1)
				my_dict[ls[idx]] -= 1
				if my_dict[ls[idx]] == 0:
					del my_dict[ls[idx]]
				my_dict[idx] = 1
				ls[idx] = idx
				change = True
				count -= 1
				break
		if not change:
			for idx in range(len_ls):
				if ls[idx] != idx:
					last_idx = idx
			res.append(last_idx + 1)
			temp_last_idx = ls[last_idx]
			my_dict[ls[last_idx]] -= 1
			if my_dict[ls[last_idx]] == 0:
				del my_dict[ls[last_idx]]
			my_dict[len_ls] = 1
			ls[last_idx] = len_ls
	print(len(res))
	res = list(map(str, res))
	print(' '.join(res))


import sys

def input():
	return sys.stdin.readline().rstrip()

def input_split():
	return [int(i) for i in input().split()]

def isSorted(a):
	for i in range(1, len(a)):
		if a[i] < a[i - 1]:
			return False
	return True

def findmex(a, n):
	pres = [False for i in range(n + 1)]
	for i in a:
		pres[i] = True
	i = 0
	while i < n and pres[i] == True:
		i += 1
	return i
t = int(input())
for tests in range(t):
	n = int(input())
	a = input_split()
	rptr = n - 1
	ops = []
	while not isSorted(a):
		m = findmex(a, n)
		if m > rptr:
			a[rptr] = m
			ops.append(rptr + 1)
			rptr -= 1
		else:
			ops.append(m + 1)
			a[m] = m
	print(len(ops))
	print(*ops, sep=' ')


def ok(a):
	for i in range(1, len(a)):
		if a[i] < a[i - 1]:
			return False
	return True

def getMex(a):
	vis = [0] * (n + 1)
	for x in a:
		vis[x] = 1
	Mex = 0
	while vis[Mex]:
		Mex += 1
	return Mex
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	op = []
	while ok(a) == False:
		cur = getMex(a)
		idx = cur
		if idx == n:
			for i in range(n):
				if a[i] != i:
					idx = i
					break
		a[idx] = cur
		op.append(idx + 1)
	print(len(op))
	print(' '.join((str(i) for i in op)))


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * (n + 1)

	def inc():
		for i in range(n - 1):
			if a[i] > a[i + 1]:
				return False
		return True

	def calc():
		for i in range(n + 1):
			c[i] = 0
		for i in a:
			c[i] += 1
		for i in range(n + 1):
			if not c[i]:
				return i
		return n + 1
	ans = []
	while not inc():
		x = calc()
		if x >= n:
			y = 0
			while y < n and a[y] == y:
				y += 1
			a[y] = x
			ans.append(y)
		else:
			a[x] = x
			ans.append(x)
	print(len(ans))
	print(*map(lambda x: x + 1, ans))
t = int(input())
for _ in range(t):
	solve()


from collections import Counter

def mex(arr, m):
	s = set(arr)
	ans = []
	i = 0
	while len(ans) != m:
		if i not in s:
			ans.append(i)
		i += 1
	return ans[::-1]

def correct(arr):
	for i in range(1, n):
		if arr[i] < arr[i - 1]:
			return False
	return True
for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = Counter(a)
	ans = []
	loc = {}
	for i in range(n):
		if a[i] in loc:
			loc[a[i]][i] = 1
		else:
			loc[a[i]] = {i: 1}
	for i in range(n):
		if a[i] != i:
			minn = i
			break
	i = 0
	while not correct(a):
		x = mex(a, 1)
		x = x[0]
		if x >= n:
			while a[minn] == minn:
				minn += 1
			for j in loc[minn]:
				a[j] = x
				ans.append(j + 1)
				d = j
				break
			del loc[minn][d]
			if a[j] in loc:
				loc[a[j]][j] = 1
			else:
				loc[a[j]] = {j: 1}
		else:
			del loc[a[x]][x]
			a[x] = x
			ans.append(x + 1)
			if a[x] not in loc:
				loc[a[x]] = {x: 1}
			else:
				loc[a[x]][x] = 1
		i += 1
	print(len(ans))
	print(*ans)


from collections import Counter
tests = int(input())

def find_mex(ind_pos):
	for (i, l) in enumerate(ind_pos):
		if len(l) == 0:
			return i

def inc(arr):
	if len(arr) < 2:
		return True
	else:
		for i in range(1, len(arr)):
			if arr[i - 1] > arr[i]:
				return False
		return True
for _ in range(tests):
	n = int(input())
	arr = [int(a) for a in input().strip().split(' ')]
	ind_pos = [[] for _ in range(n + 1)]
	for (i, a) in enumerate(arr):
		ind_pos[a].append(i)
	out = []
	for i in range(n):
		if inc(arr[i:]):
			break
		while True:
			mex = find_mex(ind_pos)
			if mex < n and arr[mex] != mex:
				ind_pos[arr[mex]].remove(mex)
				out.append(mex + 1)
				arr[mex] = mex
				ind_pos[mex].append(mex)
			else:
				break
		if inc(arr[i:]):
			break
		if arr[i] != i:
			for ind in ind_pos[i]:
				out.append(ind + 1)
				mex = find_mex(ind_pos)
				ind_pos[mex].append(ind)
				arr[ind] = mex
			ind_pos[i] = [i]
			ind_pos[arr[i]].pop(0)
			out.append(i + 1)
			arr[i] = i
	print(len(out))
	[print(a, end=' ') for a in out]
	print()


n = int(input())

def heapify(a, idx):
	if idx != 0:
		if a[idx] < a[int((idx - 1) / 2)]:
			(a[idx], a[int((idx - 1) / 2)]) = (a[(idx - 1) / 2], a[idx])
			heapify(a, int((idx - 1) / 2))

def maintain(a, idx):
	mxidx = idx
	for i in range(idx * 2 + 1, idx * 2 + 3):
		if i < len(a):
			if a[mxidx] > a[i]:
				mxidx = i
	if a[mxidx] < a[idx]:
		(a[mxidx], a[idx]) = (a[idx], a[mxidx])
		maintain(a, mxidx)
while n > 0:
	t = int(input())
	arr = [int(x) for x in input().split()]
	mexes = []
	freq = [0] * (t + 1)
	ans = []
	opers = 0
	for i in range(t):
		freq[arr[i]] += 1
	for i in range(t + 1):
		if freq[i] == 0:
			mexes.append(i)
			heapify(mexes, len(mexes) - 1)
	while len(mexes) > 1:
		ans.append(mexes[0])
		opers += 1
		freq[arr[mexes[0]]] -= 1
		if freq[arr[mexes[0]]] == 0:
			mexes.append(arr[mexes[0]])
		arr[ans[-1]] = ans[-1]
		(mexes[0], mexes[-1]) = (mexes[-1], mexes[0])
		mexes.pop(-1)
		maintain(mexes, 0)
	for i in range(t):
		if i != arr[i]:
			if i == mexes[0]:
				mexes[0] = arr[i]
				arr[i] = i
				opers += 1
				ans.append(i)
			else:
				opers += 2
				idx = arr.index(i)
				ans.append(idx)
				ans.append(i)
				arr[idx] = mexes[0]
				mexes[0] = arr[i]
				arr[i] = i
	print(opers)
	for i in range(len(ans)):
		print(ans[i] + 1, end=' ')
	print()
	n -= 1


def check(arr):
	if arr == list(range(len(arr))):
		return False
	return True

def mex(arr):
	n = len(arr)
	s = set(arr)
	for i in range(n + 1):
		if i not in s:
			return i
for _ in range(int(input())):
	n = int(input())
	arr = [int(c) for c in input().split()]
	ans = []
	while check(arr):
		m = mex(arr)
		if m < n:
			ans.append(m + 1)
			arr[m] = m
		else:
			j = 0
			while arr[j] == j:
				j += 1
			ans.append(j + 1)
			arr[j] = m
	print(len(ans))
	print(*ans)


def find():
	global n
	for i in range(n + 1):
		if cnt[i] == 0:
			return i

def isValid():
	global n
	for i in range(n - 1):
		if arr[i + 1] < arr[i]:
			return False
	return True
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	r = [i for i in range(n)]
	cnt = [0] * (n + 1)
	res = []
	rescnt = 0
	k = 0
	for i in range(n):
		cnt[arr[i]] += 1
	while not isValid():
		ind = find()
		if ind == n:
			for j in range(n):
				if j != arr[j]:
					cnt[arr[j]] -= 1
					cnt[ind] += 1
					arr[j] = ind
					res.append(j + 1)
					break
			else:
				break
		else:
			cnt[arr[ind]] -= 1
			arr[ind] = ind
			cnt[ind] += 1
			res.append(ind + 1)
		rescnt += 1
	print(rescnt)
	for i in range(rescnt):
		print(res[i], end=' ')
	print()


def MEX(Arr, n):
	s = set(Arr)
	for i in range(n + 1):
		if i not in s:
			return i
for _ in range(int(input())):
	n = int(input())
	Arr = list(map(int, input().split()))
	ans = []
	count_ans = 0
	while True:
		if Arr == sorted(Arr):
			break
		a = MEX(Arr, n)
		if a == n:
			for i in range(n):
				if Arr[i] != i:
					Arr[i] = n
					count_ans += 1
					ans.append(i + 1)
					break
		elif Arr[a] != a:
			Arr[a] = a
			count_ans += 1
			ans.append(a + 1)
	print(count_ans)
	print(*ans)


def inp():
	return int(input())

def inlt():
	l = input().split()
	for i in range(len(l)):
		l[i] = int(l[i])
	return l

def insr():
	s = input()
	return list(s[:len(s)])

def s_to_int(a):
	for i in range(len(a)):
		a[i] = int(a[i])

def factors(n):
	res = []
	t = 1
	while t * t <= n:
		if t * t == n:
			res.append(t)
		if n % t == 0:
			res.append(t)
			res.append(n // t)
		t += 1
	res.sort()
	return res

def compact_factors(n):
	res = []
	t = 2
	while t * t <= n:
		cnt = 0
		while n % t == 0:
			cnt += 1
			n //= t
		if cnt != 0:
			res.append([t, cnt])
		t += 1
	return res

def binary_search(l, target, lp, rp):
	mid = (lp + rp) // 2
	if l[mid] == target:
		return mid
	elif l[mid] > target:
		binary_search(l, target, lp, mid - 1)
	elif l[mid] < target:
		binary_search(l, target, mid + 1, rp)
	elif lp >= rp:
		return -1
n = inp()
for i in range(n):
	m = inp()
	l = inlt()
	t = 0
	res = []
	while t < m:
		t = 0
		while t in l:
			t += 1
		if t >= m:
			break
		else:
			l[t] = t
			res.append(t + 1)
	for j in range(m):
		if l[j] != j:
			list = []
			for k in range(m):
				if l[k] == j:
					t = 0
					while t in l:
						t += 1
					l[k] = t
					res.append(k + 1)
			l[j] = j
			res.append(j + 1)
	print(len(res))
	ans = ''
	for x in res:
		ans += str(x) + ' '
	print(ans)


t = int(input())

def find_mex(arr, n):
	for val in range(n + 1):
		if not val in arr:
			return val
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	k = 0
	indexes = []
	while sorted(arr) != arr:
		mex = find_mex(arr, n)
		index_to_swap = mex
		if mex < n:
			arr[mex] = mex
		else:
			for i in range(n + 1):
				if i != arr[i]:
					index_to_swap = i
					break
		arr[index_to_swap] = mex
		indexes.append(index_to_swap + 1)
	print(len(indexes))
	print(' '.join(map(str, indexes)))


from heapq import *
import sys
sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
for _ in range(II()):
	n = II()
	aa = LI()
	cnt = [0] * (n + 1)
	ans = []
	for a in aa:
		cnt[a] += 1
	hp = []
	for a in range(n + 1):
		if cnt[a] == 0:
			heappush(hp, a)
	while hp:
		a = heappop(hp)
		i = a
		cnt[a] = 1
		if a == n:
			for (j, x) in enumerate(aa):
				if j != x:
					i = j
					break
			else:
				break
		na = aa[i]
		aa[i] = a
		ans.append(i + 1)
		cnt[na] -= 1
		if cnt[na] == 0:
			heappush(hp, na)
	print(len(ans))
	print(*ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def mex(a):
	st = set()
	for i in a:
		st.add(i)
	ans = 0
	while ans in st:
		ans += 1
	return ans
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	f = 0
	ss = set()
	for i in range(1, n + 1):
		ss.add(i)
	while True:
		m = mex(a)
		if m == n:
			for i in ss:
				ans += [i]
				a[i - 1] = n
				break
		else:
			a[m] = m
			ans += [m + 1]
			if m + 1 in ss:
				ss.remove(m + 1)
			f += 1
			if f == n:
				break
	print(len(ans))
	print(*ans)


import os
import sys
from io import BytesIO, IOBase
profile = 0
pypy = 1

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

def check_dc(a):
	n = len(a)
	for i in range(1, n):
		if a[i] < a[i - 1]:
			return False
	return True

def mex_calc(a):
	ch = 0
	st = set(a)
	while ch in st:
		ch += 1
	return ch

def main():
	T = iin()
	while T:
		T -= 1
		n = iin()
		a = lin()
		ans = []
		while not check_dc(a):
			mex = mex_calc(a)
			if mex == n:
				for i in range(n):
					if a[i] != i:
						a[i] = mex
						ans.append(i + 1)
						break
			else:
				ans.append(mex + 1)
				a[mex] = mex
		print(len(ans))
		print(*ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if pypy:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
if profile:
	import cProfile
	cProfile.run('main()')
else:
	main()


import sys
input = sys.stdin.readline
import heapq
import copy
import math
import decimal

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	ans = 0
	for test in range(tests):
		n = inp()
		a = inlt()

		def find_mse(arr, n):
			hashm = {}
			for i in arr:
				hashm[i] = 1
			for i in range(n):
				if i not in hashm:
					return i
			return n
		ans = []
		while True:
			mse = find_mse(a, n)
			if mse != n:
				a[mse] = mse
				ans.append(mse + 1)
				continue
			flag = 0
			for i in range(n):
				if a[i] != i:
					a[i] = n
					ans.append(i + 1)
					flag = 1
					break
			if flag == 0:
				break
		print(len(ans))
		pr_list(ans)
main()


import sys
inpy = [int(x) for x in sys.stdin.read().split()]
t = inpy[0]
index = 1
for _i in range(t):
	n = inpy[index]
	index += 1
	arr = inpy[index:index + n]
	index += n
	exist = [0] * (n + 1)
	for i in arr:
		exist[i] += 1
	deal = 0
	res = []
	for _i in range(2 * n):
		mex = 0
		while exist[mex] != 0:
			mex += 1
		if mex == n:
			break
		exist[arr[mex]] -= 1
		exist[mex] += 1
		arr[mex] = mex
		res.append(mex + 1)
	for _i in range(2 * n + 1):
		while deal < n:
			if deal == arr[deal]:
				deal += 1
			else:
				break
		if deal == n:
			break
		flag = True
		mex = 0
		while exist[mex] != 0:
			mex += 1
		exist[mex] += 1
		for i in range(n):
			if arr[i] == deal:
				arr[i] = mex
				res.append(i + 1)
				exist[arr[i]] -= 1
				flag = False
				break
		if flag:
			exist[arr[deal]] -= 1
			arr[deal] = deal
			res.append(deal + 1)
	print(len(res))
	for i in res:
		print(i, end=' ')
	print()


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	mex = [0] * (n + 1)
	ans = []
	final = [i for i in range(n)]
	c = 0
	while l != final:
		c += 1
		mex = [0] * (n + 1)
		for i in l:
			mex[i] = 1
		for i in range(n + 1):
			if mex[i] == 0:
				if i == n:
					for _ in range(n):
						if l[_] != _:
							ans.append(_ + 1)
							l[_] = n
							break
					continue
				ans.append(i + 1)
				l[i] = i
				break
	print(c)
	print(*ans)


t = int(input())
for k in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	num = [0] * (n + 1)
	for i in range(n):
		num[a[i]] += 1
	mex = num.index(0)
	answ = []
	nu = 0
	while nu < n:
		if mex == n:
			kej = 0
			while kej < n and kej == a[kej]:
				kej += 1
			if kej == n:
				break
			temp = a[kej]
			a[kej] = mex
			answ.append(kej + 1)
			mex = temp
			nu -= 1
		elif a[mex] < mex:
			num[a[mex]] -= 1
			num[mex] += 1
			temp = mex
			if num[a[mex]] == 0:
				mex = a[mex]
			else:
				while num[mex] > 0:
					mex += 1
			a[temp] = temp
			answ.append(temp + 1)
		else:
			num[a[mex]] -= 1
			num[mex] += 1
			temp = mex
			while num[mex] > 0:
				mex += 1
			a[temp] = temp
			answ.append(temp + 1)
		nu += 1
	print(len(answ))
	print(*answ)


import sys
input = sys.stdin.buffer.readline

def findMEX(a, n):
	s = set(a)
	for i in range(n + 1):
		if i not in s:
			return i
t = int(input())
for _ in range(t):
	n = int(input())
	a = [abs(int(x)) for x in input().split()]
	wrongIndexes = set()
	for i in range(n):
		if a[i] != i:
			wrongIndexes.add(i)
	res = []
	while True:
		if len(wrongIndexes) == 0:
			break
		MEX = findMEX(a, n)
		if MEX == n:
			idx = next(iter(wrongIndexes))
			a[idx] = MEX
			res.append(idx)
		else:
			a[MEX] = MEX
			res.append(MEX)
			if MEX in wrongIndexes:
				wrongIndexes.remove(MEX)
	k = len(res)
	for i in range(k):
		res[i] += 1
	print(k)
	print(' '.join([str(x) for x in res]))


from sys import stdin
from bisect import bisect_left as bl
from bisect import bisect_right as br

def input():
	return stdin.readline()[:-1]

def intput():
	return int(input())

def sinput():
	return input().split()

def intsput():
	return map(int, sinput())

class RangedList:

	def __init__(self, start, stop, val=0):
		self.shift = 0 - start
		self.start = start
		self.stop = stop
		self.list = [val] * (stop - start)

	def __setitem__(self, key, value):
		self.list[key + self.shift] = value

	def __getitem__(self, key):
		return self.list[key + self.shift]

	def __repr__(self):
		return str(self.list)

	def __iter__(self):
		return iter(self.list)

def dprint(*args, **kwargs):
	if debugging:
		print(*args, **kwargs)

def mex(arr):
	arrcpy = set(arr)
	for i in range(len(arrcpy)):
		if i not in arrcpy:
			return i
	return len(arrcpy)

def perfect(arr):
	return all((arr[i] == i for i in range(len(arr))))

def find(arr):
	for i in range(len(arr)):
		if arr[i] != i:
			return i
debugging = 1
t = intput()
for _ in range(t):
	n = intput()
	a = list(intsput())
	n = len(a)
	rslt = []
	for i in range(2 * n):
		if perfect(a):
			break
		val = mex(a)
		if val == n:
			loc = find(a)
			a[loc] = val
			rslt.append(loc + 1)
		else:
			a[val] = val
			rslt.append(val + 1)
	print(len(rslt))
	print(' '.join(map(str, rslt)))


def mex(arr):
	s = set(arr)
	for i in range(len(arr) + 1):
		if i not in s:
			return i
inp = lambda : map(int, input().split(' '))
(t,) = inp()
for _ in range(t):
	(n,) = inp()
	arr = list(inp())
	st = 0
	res = []
	while st < n:
		val = mex(arr)
		if val < n:
			arr[val] = val
			res.append(val + 1)
		else:
			while st < n and arr[st] == st:
				st += 1
			if st < n:
				arr[st] = n
				res.append(st + 1)
				st += 1
	res = [str(i) for i in res]
	print(len(res))
	print(' '.join(res))


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	ANS = []
	DECIDED = [0] * n
	for i in range(n):
		if A[i] == i + 1:
			DECIDED[i] = 1
	while min(DECIDED) == 0:
		USE = [0] * (n + 3)
		for a in A:
			USE[a] = 1
		if USE[0] == 0:
			for i in range(n - 1, -1, -1):
				if DECIDED[i] == 0:
					ANS.append(i)
					A[i] = 0
					break
		else:
			MEX = -1
			for i in range(n + 3):
				if USE[i] == 0:
					MEX = i
					break
			ANS.append(MEX - 1)
			A[MEX - 1] = MEX
			DECIDED[MEX - 1] = 1
	print(len(ANS))
	print(*[a + 1 for a in ANS])


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	n = inp()
	x = ip()
	dt = {}
	for i in x:
		dt[i] = dt.get(i, 0) + 1
	mex = []
	for i in range(1010):
		if dt.get(i, 0) == 0:
			mex.append(i)
	from bisect import insort
	ans = []
	for ii in range(2):
		flag = 0
		for i in range(n):
			t = mex.pop(0)
			ind = t
			if t >= n:
				for j in range(n - 1, -1, -1):
					if x[j] != j:
						ind = j
						break
			if ind >= n:
				flag = 1
				break
			ans.append(ind + 1)
			ele = x[ind]
			x[ind] = t
			dt[ele] -= 1
			if dt[ele] == 0:
				insort(mex, ele)
			dt[t] = dt.get(t, 0) + 1
		if flag:
			break
	print(len(ans))
	print(*ans)


def mex():
	hashi = dict()
	for i in li:
		hashi[i] = 1
	for i in range(n + 1):
		if i not in hashi:
			return i
t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	hashno = dict()
	for i in range(n):
		if li[i] != i:
			hashno[i] = 1
	lo = []
	while len(hashno) > 0:
		z = mex()
		if z < n:
			li[z] = z
			lo.append(z)
			del hashno[z]
		else:
			for i in hashno:
				li[i] = n
				lo.append(i)
				break
			z = mex()
			lo.append(z)
			li[z] = z
			del hashno[z]
	print(len(lo))
	for i in lo:
		print(i + 1, end=' ')
	print()


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	ans = []
	ok = [int(i == a) for (i, a) in enumerate(A)]
	while sum(ok) < N:
		mex = 0
		sa = set(A)
		for i in range(N + 1):
			if i not in sa:
				mex = i
				break
		if mex == N:
			(mn, mni) = (N + 1, -1)
			for (i, a) in enumerate(A):
				if ok[i]:
					continue
				if a < mn:
					mn = a
					mni = i
			A[mni] = mex
			ans.append(mni + 1)
		else:
			A[mex] = mex
			ok[mex] = 1
			ans.append(mex + 1)
	print(len(ans))
	print(*ans)


import sys
from collections import defaultdict
for i in range(int(input())):
	n = int(input())
	lis = list(map(int, input().split()))
	if lis == sorted(lis):
		print(0)
		print()
		continue
	res = []
	while True:
		for i in range(n + 1):
			if i not in lis:
				mex = i
				break
		if mex < n:
			res.append(mex + 1)
			lis[mex] = mex
		else:
			for i in range(n):
				if i != lis[i]:
					res.append(i + 1)
					lis[i] = mex
					break
			else:
				break
	print(len(res))
	print(*res)


import sys, math, os
from io import BytesIO, IOBase
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = 10 ** 9
mod = 998244353
step = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for t in range(int(data())):
	n = int(data())
	a = mdata()
	s = set(a)
	i = 0
	ans = []
	while i < n:
		m = 0
		while m in s:
			m += 1
		if m == n:
			for j in range(n):
				if a[j] != j:
					break
			if a[j] == j:
				break
			a[j] = m
			ans.append(j + 1)
			i -= 1
		else:
			a[m] = m
			ans.append(m + 1)
		i += 1
		s = set(a)
	out(len(ans))
	outl(ans)


def check(arr):
	for i in range(1, len(arr)):
		if arr[i] < arr[i - 1]:
			return False
	return True

def mex(arr):
	x = [False] * (len(arr) + 1)
	for i in arr:
		x[i] = True
	for i in range(len(x)):
		if not x[i]:
			return i
	return 0
test_case = int(input())
for _ in range(test_case):
	n = int(input())
	arr = list(map(int, input().split()))
	x = n
	index = []
	while not check(arr):
		m = mex(arr)
		if m == 0:
			arr[0] = m
			index.append(m + 1)
		elif m == x:
			arr[m - 1] = x
			x -= 1
			index.append(m)
		else:
			arr[m] = m
			index.append(m + 1)
	print(len(index))
	for i in index:
		print(i, end=' ')
	print()


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.buffer.readline

	def MEX(A):
		N = len(A)
		cnt = [0] * (N + 1)
		for a in A:
			cnt[a] += 1
		for i in range(N + 1):
			if cnt[i] == 0:
				return i
	for _ in range(int(input())):
		N = int(input())
		A = list(map(int, input().split()))
		fixed = 0
		for (i, a) in enumerate(A):
			if i == a:
				fixed += 1
		ans = []
		while True:
			if fixed == N:
				break
			m = MEX(A)
			if m < N:
				A[m] = m
				ans.append(m + 1)
				fixed += 1
			else:
				for (i, a) in enumerate(A):
					if i != a:
						A[i] = N
						ans.append(i + 1)
						break
		assert len(ans) <= 2 * N
		print(len(ans))
		print(*ans)
main()


def mex(A):
	A = set(A)
	for i in range(1001):
		if i not in A:
			return i
	assert False

def ans(A):
	ops = []
	while True:
		m = mex(A)
		if 0 <= m < len(A):
			ops += [m]
			A[m] = m
		else:
			assert m == len(A)
			if sorted(A) == A:
				break
			for i in range(len(A)):
				if i != A[i]:
					ops += [i]
					A[i] = m
					break
	assert len(ops) <= 2 * len(A)
	print(len(ops))
	print(' '.join((str(x + 1) for x in ops)))
T = int(input())
for _ in range(T):
	input()
	A = input().split(' ')
	A = list(map(int, A))
	ans(A)


from collections import defaultdict as dc
from collections import Counter
from heapq import *
import math
from bisect import bisect_left, bisect
import sys
from collections import deque as dq
from heapq import heapify, heappush, heappop
mod = 10 ** 9 + 7

def sinp():
	p = str(sys, stdin.readline())
	return p

def seive(n):
	p = [0] * (n + 1)
	for i in range(2, n):
		if p[i] == 0:
			for j in range(2 * i, n + 1, i):
				p[i] = 1
	return p

def lower_bound(a, i, n):
	return bisect_left(a, i)

def upper_bound(a, i, n):
	return n - bisect_left(a, i)

def inp():
	p = int(sys.stdin.readline())
	return p

def line():
	p = list(map(int, sys.stdin.readline().split()))
	return p

def read_mat():
	n = inp()
	a = []
	for i in range(n):
		a.append(line())
	return a

def ind(a):
	return ord(a) - ord('A')

def digit(n):
	s = str(n)
	p = 0
	for i in s:
		p += int(i) ** 2
	return p

def check(s, k):
	for i in range(7):
		if s[i] != '?' and s[i] != k[i]:
			return 0
	return 1

def solve(n, a):
	p = dc(int)
	for i in a:
		p[i] += 1

	def mex():
		q = []
		for i in range(n + 1):
			if p[i] == 0:
				return i
	ans = []
	for i in range(n):
		while a[i] != i:
			x = mex()
			if x < n and a[x] != x:
				ans.append(x + 1)
				p[a[x]] -= 1
				a[x] = x
				p[x] += 1
			else:
				j = a.index(i)
				ans.append(j + 1)
				p[a[j]] -= 1
				a[j] = x
				p[x] += 1
	print(len(ans))
	print(*ans)
t = inp()
for _ in range(t):
	n = inp()
	a = line()
	solve(n, a)


import copy
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	mex = 0
	use = [0 for x in range(n + 1)]
	for i in range(n):
		use[a[i]] += 1
	done = False
	ct = 0
	ans = []
	while not done:
		for i in range(n + 1):
			if use[i] == 0:
				mex = i
				break
		for i in range(n):
			if mex == n:
				if a[i] != i:
					tem = copy.copy(a[i])
					ans.append(i + 1)
					a[i] = n
					use[n] += 1
					ct += 1
					if a[tem] != tem:
						ans.append(tem + 1)
						use[a[tem]] -= 1
						a[tem] = tem
						ct += 1
					break
			if mex < n:
				if a[mex] != mex:
					ans.append(mex + 1)
					use[a[mex]] -= 1
					a[mex] = mex
					use[a[mex]] += 1
					ct += 1
					break
		for i in range(1, n):
			if a[i] < a[i - 1]:
				done = False
				break
			else:
				done = True
	print(ct)
	print(*ans)


import sys
from math import ceil, sqrt, sin, pi, tan
from collections import defaultdict
read = sys.stdin.buffer.readline
import heapq
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())
for _ in range(cin()):
	n = cin()
	a = li()
	b = [0] * (n + 1)
	vis = [0] * n
	for i in range(n):
		b[a[i]] += 1
		if a[i] == i:
			vis[i] = 1
	mx = n
	for i in range(n):
		if b[i] == 0:
			mx = i
			break
	ans = []
	pic = -1
	while True:
		if mx == n:
			pic = -1
			for i in range(n - 1, -1, -1):
				if vis[i] == 0:
					pic = i
					break
		else:
			pic = mx
		if pic == -1:
			break
		temp = a[pic]
		a[pic] = mx
		b[temp] -= 1
		b[mx] += 1
		mx = n
		for i in range(n):
			if b[i] == 0:
				mx = i
				break
		ans.append(pic)
		if pic == a[pic]:
			vis[pic] = 1
	print(len(ans))
	for el in ans:
		print(el + 1, end=' ')
	print()