The city where Mocha lives in is called Zhijiang. There are $n+1$ villages and $2n-1$ directed roads in this city.

There are two kinds of roads:

$n-1$ roads are from village $i$ to village $i+1$, for all $1\leq i \leq n-1$.

$n$ roads can be described by a sequence $a_1,\ldots,a_n$. If $a_i=0$, the $i$-th of these roads goes from village $i$ to village $n+1$, otherwise it goes from village $n+1$ to village $i$, for all $1\leq i\leq n$.

Mocha plans to go hiking with Taki this weekend. To avoid the trip being boring, they plan to go through every village exactly once. They can start and finish at any villages. Can you help them to draw up a plan?


-----Input-----

Each test contains multiple test cases.

The first line contains a single integer $t$ ($1 \le t \le 20$) — the number of test cases. Each test case consists of two lines.

The first line of each test case contains a single integer $n$ ($1 \le n \le 10^4$) — indicates that the number of villages is $n+1$.

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 1$). If $a_i=0$, it means that there is a road from village $i$ to village $n+1$. If $a_i=1$, it means that there is a road from village $n+1$ to village $i$.

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^4$.


-----Output-----

For each test case, print a line with $n+1$ integers, where the $i$-th number is the $i$-th village they will go through. If the answer doesn't exist, print $-1$.

If there are multiple correct answers, you can print any one of them.


-----Examples-----

Input
2
3
0 1 0
3
1 1 0
Output
1 4 2 3 
4 1 2 3


-----Note-----

In the first test case, the city looks like the following graph:

So all possible answers are $(1 \to 4 \to 2 \to 3)$, $(1 \to 2 \to 3 \to 4)$.

In the second test case, the city looks like the following graph:

So all possible answers are $(4 \to 1 \to 2 \to 3)$, $(1 \to 2 \to 3 \to 4)$, $(3 \to 4 \to 1 \to 2)$, $(2 \to 3 \to 4 \to 1)$.

Difficulty: EASY
Tags: Graph algorithms

Constructive algorithms

Starter code:

Solutions:
N = int(input())
for _ in range(N):
	n = int(input())
	nums = [0] + list(map(int, input().strip().split())) + [1]
	for (i, (cur_r, next_r)) in enumerate(zip(nums[:], nums[1:])):
		if cur_r == 0 and next_r == 1:
			break
	out_nums = list(range(1, i + 1)) + [n + 1] + list(range(i + 1, n + 1))
	print(' '.join(map(str, out_nums)))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr[0] == 1:
		res = [n + 1]
		res += [i for i in range(1, n + 1)]
		print(*res)
	elif arr[-1] == 0:
		res = [i for i in range(1, n + 2)]
		print(*res)
	else:
		found = False
		for i in range(n - 1):
			if arr[i] == 0 and arr[i + 1] == 1:
				found = True
				res = [i for i in range(1, i + 2)]
				res += [n + 1]
				res += [i for i in range(i + 2, n + 1)]
				print(*res)
			if found:
				break
		if not found:
			print(-1)


t = int(input())
while t:
	t -= 1
	te = int(input())
	a = list(map(int, input().split()))
	if a[0] == 1:
		print(te + 1, end=' ')
		for i in range(te):
			print(i + 1, end=' ')
	elif a[-1] == 0:
		for i in range(te + 1):
			print(i + 1, end=' ')
	else:
		for i in range(te - 1):
			if a[i] == 0 and a[i + 1] == 1:
				print(i + 1, te + 1, end=' ')
				break
			else:
				print(i + 1, end=' ')
		i += 1
		while i + 1 <= te:
			print(i + 1, end=' ')
			i += 1
	print('')


from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	if n == 1:
		if a[0] == 0:
			print(1, 2)
		else:
			print(2, 1)
		continue
	if a[-1] == 0:
		print(*[i for i in range(1, n + 2)])
		continue
	if sum(a) == n:
		print(*[n + 1] + [i for i in range(1, n + 1)])
		continue
	ans = []
	ok = 0
	for i in range(n - 1):
		if ok:
			ans.append(i + 1)
			continue
		if a[i] == 0 and a[i + 1] == 1:
			ok = 1
			ans.append(i + 1)
			ans.append(n + 1)
		else:
			ans.append(i + 1)
	ans.append(n)
	print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	la = list(map(int, input().split()))
	intervene = n
	for i in range(n):
		if la[i] == 1:
			intervene = i
			break
	ans = []
	for i in range(0, n + 1):
		if i != 0:
			ans.append(i)
		if i == intervene:
			ans.append(n + 1)
	print(*ans)


from __future__ import division, print_function
import os, sys
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

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

def fi():
	return float(input())

def si():
	return input()

def msi():
	return map(str, input().split())

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

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

def lsi():
	return list(msi())

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	return x * y // gcd(x, y)
mod = 1000000007

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1
from math import log, factorial, cos, tan, sin, radians, floor, sqrt, log2
import bisect
import random
import string
from decimal import *

def reverse(x):
	return x[::-1]

def main():
	n = ii()
	a = li()
	ans = []
	for i in range(n):
		if a[i] == 1:
			for j in range(1, i + 1):
				ans.append(j)
			ans.append(n + 1)
			for j in range(i + 1, n + 1):
				ans.append(j)
			print(*ans)
			return
	for i in range(1, n + 2):
		ans.append(i)
	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')

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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(ii()):
	main()


import sys
input = sys.stdin.readline

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

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

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

def input_int_gen():
	return map(int, input().split())
tests = inp()
for _ in range(tests):
	n = inp()
	roads = input_list()
	ret = []
	for (idx, road) in enumerate(roads):
		if road == 0:
			ret.append(idx + 1)
		if road == 1:
			ret.append(n + 1)
			ret.extend(list(range(idx + 1, n + 1)))
			break
	else:
		ret.append(n + 1)
	print(' '.join([str(x) for x in ret]))


t = int(input())
for i in range(t):
	n = int(input())
	w = [int(k) for k in input().split()]
	c = n
	res = []
	while w and w[-1] == 1:
		w.pop()
		c -= 1
	for j in range(1, len(w) + 1):
		res.append(j)
	res.append(n + 1)
	for j in range(len(w) + 1, n + 1):
		res.append(j)
	print(' '.join([str(k) for k in res]))


T = int(input())
for t in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = list(map(str, range(1, n + 1)))
	if arr[0] == 1:
		print(str(n + 1) + ' ' + ' '.join(ans))
		continue
	if arr[-1] == 0:
		print(' '.join(ans) + ' ' + str(n + 1))
		continue
	for i in range(n):
		if arr[i] == 1:
			print(' '.join(ans[:i] + [str(n + 1)] + ans[i:]))
			break


import math
from collections import *

def solve():
	n = int(input())
	a = [int(i) for i in input().split()]
	if a[0] == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
		return
	elif a[n - 1] == 0:
		for i in range(1, n + 2):
			print(i, end=' ')
		print()
		return
	else:
		for i in range(n - 1):
			if a[i] == 0 and a[i + 1] == 1:
				for i in range(1, i + 2):
					print(i, end=' ')
				print(n + 1, end=' ')
				for i in range(i + 1, n + 1):
					print(i, end=' ')
				print()
				return
	print(-1)
t = int(input())
for _ in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if l[-1] == 0:
		print(*range(1, n + 2))
	elif l[0] == 1:
		print(n + 1, *range(1, n + 1))
	else:
		for i in range(1, n):
			if l[i - 1] == 0 and l[i] == 1:
				print(*range(1, i + 1), n + 1, *range(i + 1, n + 1))
				break


for i in range(int(input())):
	n = int(input())
	k = list(map(int, input().split()))
	ans = [i + 1 for i in range(0, n)]
	if k[-1] == 0:
		print(*ans + [n + 1])
	else:
		for i in range(len(k)):
			if k[i] == 1:
				res = ans[:i] + [n + 1] + ans[i:]
				break
		print(*res)


import collections
import os
import sys
from datetime import date
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 main():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

def SieveOfEratosthenes(n):
	cnt = 0
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7
import math
import statistics
from bisect import bisect_right
for __ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	f = 0
	for i in range(n):
		if f == 0 and a[i] == 1:
			f = 1
			ans.append(n + 1)
			ans.append(i + 1)
		else:
			ans.append(i + 1)
	if len(ans) != n + 1:
		ans.append(n + 1)
	print(*ans)


from sys import stdin, stdout, setrecursionlimit
from io import BytesIO, IOBase
setrecursionlimit(10000)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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
		self.BUFSIZE = 8192

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

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

	def flush(self):
		if self.writable:
			self.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')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
input = lambda : stdin.readline().rstrip('\r\n')
inp = lambda : int(input())
st = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
int_arr = lambda : list(map(int, input().strip().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().strip().split())
get_int = lambda : map(int, input().strip().split())
get_float = lambda : map(float, input().strip().split())
mod = 10 ** 9 + 7
for _ in range(inp()):
	n = inp()
	a = int_arr()
	c = 0
	for i in a:
		if i == 1:
			c += 1
	if c == 0:
		for i in range(n + 1):
			print(i + 1, end=' ')
	elif a[0] == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
	else:
		x = 0
		for i in range(n - 1):
			if a[i] == 0 and a[i + 1] == 1:
				x = i
				break
		for i in range(n):
			print(i + 1, end=' ')
			if i == x:
				print(n + 1, end=' ')
	print('')


for _ in range(int(input())):
	n = int(input())
	m = list(input().split())
	p = [i + 1 for i in range(n)]
	x = 0
	for i in range(n):
		if m[i] != '0':
			x = -1
			break
	xp = 0
	for i in range(n):
		if m[i] != '1':
			xp = -1
			break
	if xp == 0:
		p.insert(0, n + 1)
		print(*p)
	elif x == 0:
		p.append(n + 1)
		print(*p)
	else:
		for i in range(n + 1):
			if m[i] == '0' and m[i + 1 if i + 1 <= n - 1 else 0] == '1':
				k = i + 1
				if k > n:
					k = 0
				p.insert(k, n + 1)
				print(*p)
				p = -1
				break
		if p != -1:
			print(p)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	index = -1
	s = ''
	for i in reversed(range(n)):
		if a[i] == 0:
			index = i
			break
	if index == -1:
		s = str(n + 1)
		for i in range(1, n + 1):
			s += ' ' + str(i)
	else:
		for i in range(1, index + 2):
			s += str(i) + ' '
		s += str(n + 1)
		for i in range(index + 2, n + 1):
			s += ' ' + str(i)
	print(s)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	if 1 in A and 0 in A:
		if A[0] == 1:
			print(n + 1, end=' ')
			for i in range(1, n + 1):
				print(i, end=' ')
			print()
		else:
			tr = False
			for i in range(n):
				if A[i] == 0 or tr:
					print(i + 1, end=' ')
				else:
					tr = True
					print(n + 1, end=' ')
					print(i + 1, end=' ')
			print()
	elif A[0] == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
	else:
		for i in range(1, n + 2):
			print(i, end=' ')
		print()


import sys
from math import ceil, floor, modf, sqrt
from collections import deque
from heapq import heappush, heappop, heapify

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

def get_array():
	return list(get_ints())

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

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
T = int(input())
while T > 0:
	n = int(input())
	Arr = get_array()
	if Arr[0] == 1:
		ans = [n + 1] + [i for i in range(1, n + 1)]
		print(*ans)
	elif Arr[-1] == 0:
		ans = [i for i in range(1, n + 1)] + [n + 1]
		print(*ans)
	else:
		flag = 0
		for i in range(n - 1):
			if Arr[i] == 0 and Arr[i + 1] == 1:
				flag = 1
				one = i + 1
				break
		if flag == 0:
			print(-1)
		else:
			ans = [i for i in range(1, one + 1)] + [n + 1] + [i for i in range(one + 1, n + 1)]
			print(*ans)
	T -= 1


T = int(input())
while T:
	l = int(input())
	arr = list(map(int, input().split()))
	i = 0
	cond = False
	if arr[0] == 1:
		print(l + 1, end=' ')
		for ele in range(1, l + 1):
			print(ele, end=' ')
		T -= 1
		print()
		continue
	if arr[-1] == 0:
		for ele in range(1, l + 2):
			print(ele, end=' ')
		T -= 1
		print()
		continue
	while i < l:
		if arr[i] == 0:
			if i + 1 < l:
				if arr[i + 1] == 1:
					cond = True
					store = i + 1
					break
		i += 1
	if cond == False:
		print(-1)
	else:
		for i in range(1, l + 1):
			if i == store:
				print(i, l + 1, end=' ')
			else:
				print(i, end=' ')
	print()
	T -= 1


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if 1 not in a:
		for i in range(n + 1):
			print(i + 1, end=' ')
	else:
		ind = a.index(1)
		for i in range(ind):
			print(i + 1, end=' ')
		else:
			print(n + 1, end=' ')
		for i in range(ind, n):
			print(i + 1, end=' ')
		print()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	f = 0
	a = []
	for i in range(n - 1):
		a.append(i + 1)
		if f == 0 and arr[i] == 0 and (arr[i + 1] == 1):
			a.append(n + 1)
			f = 1
	a.append(n)
	if f == 1:
		ans = a
	elif arr[0] == 1:
		ans = [n + 1]
		for i in range(1, n + 1):
			ans.append(i)
	elif arr[n - 1] == 0:
		ans = []
		for i in range(1, n + 2):
			ans.append(i)
	else:
		ans = [-1]
	print(*ans)


for i in range(int(input())):
	a = int(input())
	c = [int(x) for x in input().split()]
	x = -1
	if a == 1:
		if c[0] == 1:
			print(2, 1, sep=' ')
		else:
			print(1, 2, sep=' ')
		continue
	if c[0] == 1:
		print(a + 1, end=' ')
		for i in range(a):
			print(i + 1, end=' ')
		print()
	else:
		for i in range(len(c) - 1):
			if c[i] == 0 and c[i + 1] != 1:
				print(i + 1, end=' ')
			else:
				print(i + 1, end=' ')
				x = i + 1
				break
		if x != -1:
			print(a + 1, end=' ')
			for i in range(x, a):
				print(i + 1, end=' ')
			print()
		else:
			print(a, a + 1, sep=' ')


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	if arr[0] == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
		continue
	if arr[n - 1] == 0:
		for i in range(1, n + 2):
			print(i, end=' ')
		print()
		continue
	flag = False
	for i in range(n - 1):
		if arr[i] == 0 and arr[i + 1] == 1:
			flag = True
			for j in range(1, i + 2):
				print(j, end=' ')
			print(n + 1, end=' ')
			for j in range(i + 2, n + 1):
				print(j, end=' ')
			print()
			break
	if flag == False:
		print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	x = [int(x) for x in input().split()]
	if x[-1] == 0:
		for i in range(n):
			print(i + 1, end=' ')
		print(n + 1)
	elif x[0] == 1:
		print(n + 1, end=' ')
		for i in range(n):
			print(i + 1, end=' ')
		print()
	else:
		r = -1
		for i in range(n - 1):
			if x[i] == 0 and x[i + 1] == 1:
				r = i
				break
		if r == -1:
			print(-1)
		else:
			for i in range(1, r + 2):
				print(i, end=' ')
			print(n + 1, end=' ')
			for i in range(r + 2, n + 1):
				print(i, end=' ')
			print()


t = int(input())
while t:
	t -= 1
	n = int(input())
	ls = list(map(int, input().split()))
	if ls[-1] == 0:
		print(*list(range(1, n + 2)))
	elif ls[0] == 1:
		print(n + 1, end=' ')
		print(*list(range(1, n + 1)))
	else:
		for i in range(n):
			if ls[i] == 0:
				print(i + 1, end=' ')
			else:
				print(n + 1, end=' ')
				print(*list(range(i + 1, n + 1)))
				break


def fun(ls, n):
	if ls[-1] == 0:
		print(*[i for i in range(1, n + 2)])
	else:
		ans = []
		possible = False
		last_value = None
		for i in range(n - 1):
			index_stw1 = i + 1
			cur_val = ls[i]
			next_val = ls[i + 1]
			if cur_val == 0 and next_val == 1:
				ans.append(index_stw1)
				ans.append(n + 1)
				last_value = index_stw1 + 1
				possible = True
				break
			ans.append(index_stw1)
		if possible:
			ans.extend(range(last_value, n + 1))
			print(*ans)
			return
		if ls[0] == 1:
			print(*[n + 1] + [i for i in range(1, n + 1)])
		else:
			print(-1)
T = int(input())
for i in range(T):
	n = int(input())
	ls = list(map(int, input().split()))
	fun(ls, n)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input().split()))
	s = ''
	if n == 1:
		if l1[0] == 0:
			print('1 2')
		else:
			print('2 1')
	elif l1[n - 1] == 0:
		for i in range(1, n + 2):
			s += str(i) + ' '
		print(s)
	elif l1[0] == 1:
		s += str(n + 1) + ' '
		for j in range(1, n + 1):
			s += str(j) + ' '
		print(s)
	else:
		p = ''
		for d in range(n):
			p += str(l1[d])
		if '01' in p:
			for y in range(1, p.index('01') + 2):
				s += str(y) + ' '
			s += str(n + 1) + ' '
			for x in range(p.index('01') + 2, n + 1):
				s += str(x) + ' '
			print(s)
		else:
			print(-1)


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	if arr[-1] == 0:
		return [i for i in range(1, n + 2)]
	else:
		inter = -1
		for i in range(1, n):
			if arr[i - 1] == 0 and arr[i] != 0:
				inter = i
				break
	if inter == -1:
		return [-1] if arr[0] == 0 else [n + 1] + [i for i in range(1, n + 1)]
	ans = [i for i in range(1, inter + 1)] + [n + 1] + [i for i in range(inter + 1, n + 1)]
	return ans
for _ in range(int(input())):
	print(*solve())


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	out = ''
	c = True
	for k in range(0, len(a)):
		if a[k] == 1 and c:
			out += str(n + 1) + ' '
			c = False
		out += str(k + 1) + ' '
	if c:
		out += str(n + 1)
	print(out)


t = int(input())
for x in range(t):
	yes = False
	n = int(input())
	arr = list(map(int, input().split()))
	temp = []
	if arr[0] == 1:
		temp = [n + 1]
		for b in range(1, n + 1):
			temp.append(b)
			yes = True
	elif arr[n - 1] == 0:
		for b in range(1, n + 1):
			temp.append(b)
		temp.append(n + 1)
		yes = True
	if not yes:
		done = False
		for i in range(0, n - 1):
			if done:
				break
			if arr[i] == 0 and arr[i + 1] == 1:
				for x in range(1, i + 2):
					temp.append(x)
				temp.append(n + 1)
				for z in range(i + 2, n + 1):
					temp.append(z)
				done = True
	for text in temp:
		print(text, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a[-1] == 0:
		for i in range(1, n + 2):
			print(i, end=' ')
		print()
	elif a[0] == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
	else:
		for i in range(n - 1):
			if a[i] == 0 and a[i + 1] == 1:
				for j in range(1, i + 2):
					print(j, end=' ')
				print(n + 1, end=' ')
				for j in range(i + 2, n + 1):
					print(j, end=' ')
				break
		print()


import io, os
for _ in range(int(input())):
	N = int(input())
	arr = list(map(int, input().split()))
	if arr[-1] == 0:
		ans = [str(i) for i in range(1, N + 2)]
		print(' '.join(ans))
	elif arr[0] == 1:
		ans = [str(i) for i in range(1, N + 1)]
		ans = [str(N + 1)] + ans
		print(' '.join(ans))
	else:
		ret = False
		ans = []
		i = 0
		while i < N:
			if arr[i] == 0:
				ans.append(i + 1)
				i += 1
			else:
				ans.append(N + 1)
				i += 1
				break
		while i < N + 1:
			ans.append(i)
			i += 1
		ans = [str(ans[i]) for i in range(len(ans))]
		print(' '.join(ans))


for ik in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if l[-1] == 0:
		for i in range(n + 1):
			print(i + 1, end=' ')
		print()
		continue
	f = -1
	for i in range(n - 1):
		if l[i] == 0 and l[i + 1] == 1:
			f = i + 1
			break
	if f == -1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
		continue
	for i in range(f):
		print(i + 1, end=' ')
	print(n + 1, f + 1, end=' ')
	for i in range(f + 2, n + 1):
		print(i, end=' ')
	print()


def fun(arr, n):
	if arr[0]:
		print(n + 1, end=' ')
		for i in range(n):
			print(i + 1, end=' ')
		return
	for i in range(n - 1):
		if not arr[i] and arr[i + 1]:
			for j in range(i + 1):
				print(j + 1, end=' ')
			print(n + 1, end=' ')
			for j in range(i + 1, n):
				print(j + 1, end=' ')
			return
	for i in range(1, n + 2):
		print(i, end=' ')
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	fun(arr, n)
	print()


import os, sys
input = lambda : sys.stdin.buffer.readline().rstrip(b'\r\n')

def dbp(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)
a_str = lambda : input().decode('ascii')
get_int_list = lambda : [int(x) for x in input().split()]
join_str = lambda l, ch=' ': ch.join((str(x) for x in l))

def do_thing():
	n = int(input())
	alist = get_int_list()
	if alist[n - 1] == 0:
		return join_str([i for i in range(1, n + 2)])
	if alist[0] == 1:
		return join_str([n + 1] + [i for i in range(1, n + 1)])
	for i in range(n - 1):
		if alist[i] == 0 and alist[i + 1] == 1:
			return join_str([j for j in range(1, i + 2)] + [n + 1] + [j for j in range(i + 2, n + 1)])
	return -1

def multicase():
	maxcc = int(input().strip())
	for cc in range(maxcc):
		print(do_thing())
multicase()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	if l[-1] == 0:
		p = [i for i in range(1, n + 2)]
		print(*p)
	else:
		c = 0
		p = []
		for i in range(n):
			if l[i] == 1:
				c = i
				break
			else:
				p.append(i + 1)
		p.append(n + 1)
		for i in range(c + 1, n + 1):
			p.append(i)
		print(*p)


import math
import sys
import collections
import bisect
import time
import random
from itertools import permutations

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

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

def get_string():
	return sys.stdin.readline().strip()
for t in range(int(input())):
	n = int(input())
	arr = get_list()
	cc = [set() for i in range(n + 2)]
	for (i, j) in enumerate(arr):
		if i < n - 1:
			cc[i + 1].add(i + 2)
		if j == 0:
			cc[i + 1].add(n + 1)
		else:
			cc[n + 1].add(i + 1)
	ans = []
	done = False
	for i in range(1, n + 1):
		if done == False:
			if i + 1 in cc[n + 1] and n + 1 in cc[i]:
				ans.append(i)
				ans.append(n + 1)
				done = True
			else:
				ans.append(i)
		else:
			ans.append(i)
		if i == n and done == False and (n + 1 in cc[i]):
			ans.append(n + 1)
	if len(ans) == n + 1:
		print(*ans)
	elif 1 in cc[n + 1] and n + 1 not in ans and (len(ans) == n):
		ans.insert(0, n + 1)
		print(*ans)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	v = int(input())
	arr = list(map(int, input().split()))
	ut = nam = -1
	for (j, i) in enumerate(arr):
		if i == 0:
			ut = j
	ans = []
	if ut == -1:
		ans.append(v + 1)
	for i in range(v):
		ans.append(i + 1)
		if ut == i:
			ans.append(v + 1)
	ans2 = [str(i) for i in ans]
	print(' '.join(ans2))


def main():
	n = int(input())
	a = list(map(int, input().split()))
	if not a[n - 1]:
		print(*[i for i in range(1, n + 2)])
		return
	if a[0]:
		print(n + 1, *[i for i in range(1, n + 1)])
		return
	for j in range(1, n):
		if a[j - 1] == 0 and a[j] == 1:
			print(*[i for i in range(1, j + 1)], n + 1, *[i for i in range(j + 1, n + 1)])
			return
	print(-1)
t = int(input())
for _ in range(t):
	main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	s = input()[:-1].replace(' ', '')
	if s[0] == '1':
		print(n + 1, *list(range(1, n + 1)))
	elif s[-1] == '0':
		print(*list(range(1, n + 2)))
	else:
		x = s.find('01')
		if x < 0:
			print(-1)
		else:
			print(*list(range(1, x + 2)), n + 1, *list(range(x + 2, n + 1)))


t = int(input())
for tc in range(t):
	n = int(input())
	s = input().replace(' ', '')
	if s[-1] == '0':
		ans = [*range(1, n + 1), n + 1]
		print(*ans)
	elif s[0] == '1':
		ans = [n + 1, *range(1, n + 1)]
		print(*ans)
	elif '01' in s:
		i = s.index('01')
		ans = [*range(1, i + 2), n + 1, *range(i + 2, n + 1)]
		print(*ans)
	else:
		print(-1)


def mochaAndHiking(n, array):
	if array[-1] == 0:
		return [x + 1 for x in range(n + 1)]
	if array[0] == 1:
		return [n + 1] + [x + 1 for x in range(n)]
	for x in range(n):
		if array[x] == 1:
			break
	ans = []
	for i in range(x):
		ans.append(i + 1)
	ans.append(n + 1)
	for i in range(x, n):
		ans.append(i + 1)
	return ans
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	ans = mochaAndHiking(n, l)
	for x in ans:
		print(x, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a[-1] == 0:
		for i in range(1, n + 1):
			print(i, end=' ')
		print(n + 1)
	else:
		temp = a.index(1) + 1
		for i in range(1, temp):
			print(i, end=' ')
		print(n + 1, end=' ')
		for i in range(temp, n):
			print(i, end=' ')
		print(n)


def solve():
	n = int(input())
	ll = list(map(int, input().split()))
	ans = []
	vapis = False
	for i in range(n):
		if ll[i] == 1:
			if not vapis:
				vapis = True
				ans.append(n + 1)
			ans.append(i + 1)
		else:
			ans.append(i + 1)
	if not vapis:
		ans.append(n + 1)
	return ans
t = int(input())
while t != 0:
	res = solve()
	print(*res)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a[0] == 1:
		ans = [i for i in range(1, n + 1)]
		print(n + 1, *ans)
	else:
		ans = []
		for i in range(n):
			ans.append(i + 1)
			if a[i] == 0 and (i < n - 1 and a[i + 1] == 1):
				ans.append(n + 1)
				for j in range(i + 2, n + 1):
					ans.append(j)
				break
			elif i == n - 1 and a[i] == 0:
				ans.append(n + 1)
		if len(ans) == n + 1:
			print(*ans)
		else:
			print(-1)


from sys import stdin
ii = lambda : int(input())
li = lambda : list(map(int, stdin.readline().strip().split()))
for _ in range(1, ii() + 1):
	n = ii()
	a = li()
	if n == 1:
		if a[0] == 0:
			print(1, 2)
		else:
			print(2, 1)
	elif n == 2:
		if a[1] == 0:
			print(1, 2, 3)
		elif a[0] == 1:
			print(3, 1, 2)
		elif a[0] == 0 and a[1] == 1:
			print(1, 3, 2)
		else:
			print(-1)
	elif a[0] == 1:
		print(*[n + 1] + [i for i in range(1, n + 1)])
	elif a[n - 1] == 0:
		print(*[i for i in range(1, n + 2)])
	else:
		l = -1
		for i in range(n - 1):
			if a[i] == 0 and a[i + 1] == 1:
				l = i
				break
		if l == -1:
			print(-1)
		else:
			for i in range(n):
				if l == i:
					print(i + 1, n + 1, end=' ')
				else:
					print(i + 1, end=' ')
			print()


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	lans = []
	if l.count(1) == 0:
		for i in range(1, n + 2):
			lans.append(i)
	elif l.count(0) == 0:
		lans.append(n + 1)
		for i in range(1, n + 1):
			lans.append(i)
	elif l[0] == 0:
		p = l.index(1) + 1
		for i in range(1, p):
			lans.append(i)
		lans.append(n + 1)
		for i in range(p, n + 1):
			lans.append(i)
	else:
		lans.append(n + 1)
		for i in range(1, n + 1):
			lans.append(i)
	print(*lans)
	t -= 1


from math import ceil, log, floor
from collections import defaultdict
import sys
import os.path
sys.setrecursionlimit(200000)
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r+')
	sys.stdout = open('output.txt', 'w')

def MI():
	return map(int, input().split())
for _ in range(int(input())):
	n = int(input())
	a = list(list(map(int, input().split())))
	if a[n - 1] == 0:
		b = [i for i in range(1, n + 2)]
		print(*b)
	else:
		last = n - 1
		for i in range(n - 1, -1, -1):
			if a[i] == 0:
				last = i
				break
		if last == n - 1:
			print(n + 1, end=' ')
			for i in range(1, n + 1):
				print(i, end=' ')
		else:
			for i in range(1, last + 2):
				print(i, end=' ')
			print(n + 1, end=' ')
			for i in range(last + 2, n + 1):
				print(i, end=' ')
			print()


import math
import collections
import bisect
import functools
import sys
t = int(input())
for __ in range(t):
	n = int(input())
	arr = list(map(int, input().strip(' ').split(' ')))
	if arr[0] == 1:
		print(str(n + 1) + ' ' + ' '.join((str(i) for i in range(1, n + 1))))
		continue
	elif arr[n - 1] == 0:
		print(' '.join((str(i) for i in range(1, n + 1))) + ' ' + str(n + 1))
		continue
	else:
		for i in range(n - 1):
			if arr[i] == 0 and arr[i + 1] == 1:
				a = ' '.join((str(i) for i in range(1, i + 2)))
				b = str(n + 1)
				c = ' '.join((str(i) for i in range(i + 2, n + 1)))
				print(a + ' ' + b + ' ' + c)
				break
		else:
			print(-1)


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	if n == 1:
		if a[0] == 0:
			print(1, 2)
		else:
			print(2, 1)
		continue
	last = -1
	for i in range(n - 1, -1, -1):
		if a[i] == 0:
			last = i
			break
	ans = [i for i in range(1, last + 2)]
	ans.append(n + 1)
	for i in range(last + 2, n + 1):
		ans.append(i)
	print(*ans)


from collections import Counter
import string
import math
import bisect
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
testcases = vary(1)
for _ in range(testcases):
	n = vary(1)
	num = array_int()
	if n == 1:
		if num[0] == 1:
			print(2, 1)
		else:
			print(1, 2)
		continue
	if num[0] == 1:
		print(n + 1, *[i for i in range(1, n + 1)])
		continue
	if num[n - 1] == 0:
		print(*[i for i in range(1, n + 2)])
	else:
		value = -1
		for i in range(n - 1):
			if num[i] == 0 and num[i + 1] == 1:
				value = i + 1
				break
		if value == -1:
			print(-1)
		else:
			for i in range(1, value + 1):
				print(i, end=' ')
			print(n + 1, end=' ')
			for i in range(value + 1, n + 1):
				print(i, end=' ')
			print()


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	if a[-1] == 0:
		print(' '.join(map(str, range(1, n + 2))))
		return
	if a[0] == 1:
		print(' '.join(map(str, [n + 1] + list(range(1, n + 1)))))
		return
	for i in range(1, n):
		if a[i - 1] == 0 and a[i] == 1:
			r = list(range(1, n + 1))
			r.insert(i, n + 1)
			print(' '.join(map(str, r)))
			return
	print(-1)
for i in range(int(input())):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	size = n
	res = []
	while a and a[-1] == 1:
		a.pop()
		size -= 1
	for i in range(1, len(a) + 1):
		res.append(i)
	res.append(n + 1)
	for i in range(len(a) + 1, n + 1):
		res.append(i)
	print(' '.join([str(i) for i in res]))


import traceback
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 = IOWrapper(sys.stdin)
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
from collections import defaultdict as dfd, Counter
from functools import lru_cache
from itertools import accumulate

def geti():
	return int(input())

def gets():
	return input()

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

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

def getinps(s):
	inps = s.split()
	m = {'i': geti, 's': gets, 'il': getil, 'sl': getsl}
	if len(inps) == 1:
		return m[s]()
	return [m[k]() for k in inps]

def get2d(nrows, ncols, n=0):
	return [[n] * ncols for r in range(nrows)]

def get_acc(a):
	return list(accumulate(a))

def get_ncr(n, r, mod=10 ** 9 + 7):
	num = den = 1
	r = min(r, n - r)
	for i in range(r):
		num = num * (n - i) % mod
		den = den * (i + 1) % mod
	return num * pow(den, mod - 2, mod) % mod

def get_nc2(n):
	return n * (n - 1) // 2

def get_npr(n, r):
	if n < r:
		return 0
	return math.factorial(n) // math.factorial(r)

def put(a):
	return ' '.join(map(str, a))
inf = float('inf')
mod = 10 ** 9 + 7

def main():
	((N,), a) = getinps('il il')
	b = list(range(1, N + 1))
	if a[-1] == 0:
		a = b + [N + 1]
		return a
	if a[0] == 1:
		a = [N + 1] + b
		return a
	for i in range(N - 1, 0, -1):
		if a[i] == 1 and a[i - 1] == 0:
			a = b[:i] + [N + 1] + b[i:]
			return a
	return [-1]
try:
	Test = geti()
	answers = []
	for _ in range(Test):
		ans = main()
		print(*ans)
except Exception as e:
	print(e)
	traceback.print_exc()


for _ in [0] * int(input()):
	n = int(input())
	a = input()
	out = [-1]
	if a[0] == '1':
		i = 0
	elif a[-1] == '0':
		i = n
	elif '0 1' in a:
		i = a.index('0 1') // 2 + 1
	out = list(range(1, i + 1)) + [n + 1] + list(range(i + 1, n + 1))
	print(*out)


def f(n, edges):
	if n == 1:
		if edges[0] == 1:
			return [2, 1]
		else:
			return [1, 2]
	if edges[-1] == 0:
		return list(range(1, n + 2))
	if edges[0] == 1:
		return [n + 1] + list(range(1, n + 1))
	ret = []
	for (i, v) in enumerate(edges[:-1]):
		ret.append(i + 1)
		if v == 0 and edges[i + 1] == 1:
			ret.append(n + 1)
			ret.append(i + 2)
			ret.extend(list(range(ret[-1] + 1, n + 1)))
			return ret
	else:
		return [-1]

def main():
	for _ in range(int(input())):
		n = int(input())
		edges = [int(i) for i in input().split()]
		a = f(n, edges)
		print(' '.join(map(str, a)))
main()


for t in range(int(input())):
	n = int(input())
	arr = input().split()
	a = sum(map(int, arr))
	if arr[-1] == '0':
		ans = [str(i + 1) for i in range(n + 1)]
		print(' '.join(ans))
	elif a == n:
		ans = [str(i + 1) for i in range(n)]
		print(str(n + 1) + ' ' + ' '.join(ans))
	else:
		idx = 0
		while idx < n - 1:
			if arr[idx] == '0' and arr[idx + 1] == '1':
				break
			idx += 1
		ans = ' '.join([str(i) for i in range(1, idx + 2)])
		ans += ' {} '.format(n + 1)
		ans += ' '.join([str(i + 1) for i in range(idx + 1, n)])
		print(ans)


import sys

def main():
	num_args = int(input())
	while num_args:
		solve()
		num_args -= 1

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	i = 0
	if a[i]:
		result = ' '.join([str(x + 1) for x in range(n)])
		result = str(n + 1) + ' ' + result
	elif not a[-1]:
		result = ' '.join([str(x + 1) for x in range(n + 1)])
	else:
		result = ''
		loop_found = False
		while i < n:
			if not i:
				result = str(i + 1)
			else:
				result = result + ' ' + str(i + 1)
			if i == n - 1:
				break
			if not a[i] and a[i + 1] and (not loop_found):
				result = result + ' ' + str(n + 1)
				result = result + ' ' + str(i + 2)
				i += 2
				loop_found = True
			else:
				i += 1
		if str(n + 1) not in result:
			sys.stdout.write(str(-1) + '\n')
			return
	sys.stdout.write(str(result) + '\n')
main()


numTests = input()
answer = []
for k in range(int(numTests)):
	n = int(input())
	data = input()
	path = [i for i in range(1, n + 2)]
	a = [int(i) for i in data.split()]
	if a[0] == 1:
		path.pop()
		path.insert(0, n + 1)
	elif a[0] == 0:
		if a[n - 1] == 1:
			for i in range(n - 1):
				if a[i] == 0 and a[i + 1] == 1:
					path.pop()
					path.insert(i + 1, n + 1)
					break
	else:
		path = -1
	answer.append(' '.join([str(j) for j in path]))
for c in answer:
	print(c)


t = int(input())
while t:
	n = int(input())
	arr = [int(i) for i in input().split()]
	x = -1
	if arr[n - 1] == 0:
		for i in range(1, n + 1):
			print(i, end=' ')
		print(n + 1)
	else:
		for k in range(n - 2, -1, -1):
			if arr[k] == 0:
				x = k
				break
		for i in range(1, x + 2):
			print(i, end=' ')
		print(n + 1, end=' ')
		for i in range(x + 2, n):
			print(i, end=' ')
		print(n)
	t -= 1


t = int(input())
for testcase in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr[0] == 1:
		print(n + 1, ' '.join([str(k) for k in range(1, n + 1)]))
	elif arr[-1] == 0:
		print(' '.join([str(k) for k in range(1, n + 1)]), n + 1)
	else:
		nums = list(range(1, n + 1))
		for k in range(n):
			if k == n - 1:
				break
			if arr[k] == 0 and arr[k + 1] == 1:
				nums.insert(k + 1, n + 1)
				break
		if k == n - 1:
			print(-1)
		else:
			print(' '.join([str(k) for k in nums]))


for s in [*open(0)][2::2]:
	n = len((s := ('00' + s[::2] + '1'))) - 2
	print(*([-1], [*range(1, (i := s.find('01'))), n, *range(i, n)])[i > 0])


test = int(input())
for t in range(test):
	n = int(input())
	ls = list(map(int, input().split()))
	a = range(1, n + 2)
	if n == 1:
		if ls[0] == 0:
			print('1 2')
		else:
			print('2 1')
		continue
	elif ls[-1] == 0:
		print(' '.join((str(i) for i in a)))
		continue
	elif ls[0] == 1:
		print(a[-1], ' '.join((str(i) for i in a[:-1])))
		continue
	else:
		for i in range(n):
			if ls[i] == 0 and ls[i + 1] == 1:
				print(' '.join((str(i) for i in a[:i + 1])), a[-1], ' '.join((str(i) for i in a[i + 1:-1])))
				break
		continue
	print(-1)


for i in range(int(input())):
	n = int(input())
	a = ''.join(input().split())
	if a[0] == '1':
		print(n + 1, ' '.join(map(str, list(range(1, n + 1)))))
		continue
	elif a[-1] == '0':
		print(' '.join(map(str, list(range(1, n + 2)))))
		continue
	elif '01' in a:
		ind = a.index('01') + 1
		for j in range(1, n + 1):
			if j == ind:
				print(j, n + 1, end=' ')
			else:
				print(j, end=' ')
		print()
		continue
	print(-1)


def sol():
	n = int(input())
	list = [int(i) for i in input().split()]
	br = 0
	if list[0] == 1:
		print(n + 1, end=' ')
		for i in range(n):
			print(i + 1, end=' ')
		print()
	elif list[n - 1] == 0:
		for i in range(n + 1):
			print(i + 1, end=' ')
		print()
	else:
		for i in range(n - 1):
			if list[i] == 0 and list[i + 1] == 1:
				br = i
				break
		for i in range(br + 1):
			print(i + 1, end=' ')
		print(n + 1, end=' ')
		for i in range(br + 1, n):
			print(i + 1, end=' ')
		print()
t = int(input())
while t > 0:
	t -= 1
	sol()


def res(l, n):
	if n == 1:
		if l[0] == 1:
			print(2, 1, sep=' ')
		else:
			print(1, 2, sep=' ')
	elif l[0] == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
	elif l[n - 1] == 0:
		for i in range(1, n + 1):
			print(i, end=' ')
		print(n + 1)
	else:
		index = -1
		for i in range(1, n):
			if l[i] == 1 and l[i - 1] == 0:
				index = i - 1
				break
		if index != -1:
			for i in range(0, n):
				if i != index:
					print(i + 1, end=' ')
				else:
					print(i + 1, end=' ')
					print(n + 1, end=' ')
			print()
		else:
			print(-1)
for t in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	res(l, n)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list()
	x = list(map(int, input().split()))
	flag = True
	for i in range(n):
		if x[i] == 0:
			a.append(False)
			flag = False
		else:
			a.append(True)
	if flag:
		way = [n + 1] + list((i for i in range(1, n + 1)))
		print(*way)
		continue
	way = []
	is_visited = False
	for i in range(n):
		way.append(i + 1)
		if not is_visited and (i == n - 1 and (not a[i]) or (not a[i] and a[i + 1])):
			way.append(n + 1)
			is_visited = True
	print(*way)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	a = []
	if l[0] == 1:
		a.append(n + 1)
		for j in range(1, n + 1):
			a.append(j)
		print(*a)
	else:
		try:
			m = l.index(1)
			for j in range(1, m + 1):
				a.append(j)
			a.append(n + 1)
			for j in range(m + 1, n + 1):
				a.append(j)
			print(*a)
		except ValueError:
			print(*list(range(1, n + 2)))


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	path = []
	if arr[0] == 1:
		path.append(n + 1)
		for i in range(1, n + 1):
			path.append(i)
		return path
	if arr[n - 1] == 0:
		for i in range(1, n + 1):
			path.append(i)
		path.append(n + 1)
		return path
	gone_once = False
	for i in range(n - 1):
		path.append(i + 1)
		if gone_once is False and arr[i] == 0 and (arr[i + 1] == 1):
			path.append(n + 1)
			gone_once = True
	path.append(n)
	if gone_once:
		return path
	return [-1]
for _ in range(int(input())):
	a = main()
	print(*a)


for _ in range(int(input())):
	l = int(input())
	a = ''.join(list(input().split()))
	if a[0] == '1':
		print(l + 1, end=' ')
		for i in range(l):
			print(i + 1, end=' ')
		print()
	elif a[-1] == '0':
		for i in range(l):
			print(i + 1, end=' ')
		print(l + 1, end=' ')
		print()
	else:
		temp = a.find('01')
		for i in range(temp + 1):
			print(i + 1, end=' ')
		print(l + 1, end=' ')
		for i in range(temp + 1, l):
			print(i + 1, end=' ')
		print()


case = int(input())
for time in range(case):
	n = int(input())
	roads = []
	rawroad = input().split()
	for i in range(n):
		roads.append(int(rawroad.pop()))
	roads.reverse()
	if roads[0] == 1:
		print(n + 1, end=' ')
		for i in range(n):
			print(i + 1, end=' ')
	elif roads[-1] == 0:
		for i in range(n + 1):
			print(i + 1, end=' ')
	else:
		for i in range(1, n):
			if roads[i] == 1:
				if roads[i - 1] == 0:
					for j in range(i):
						print(j + 1, end=' ')
					print(n + 1, end=' ')
					for j in range(i, n):
						print(j + 1, end=' ')
					break
	print('\n')


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	a = [int(x) for x in input().split()]
	to_move = -1
	if a[0]:
		print(n + 1, end=' ')
		for x in range(1, n + 1):
			print(x, end=' ')
	elif a[n - 1] == 0:
		for x in range(1, n + 1):
			print(x, end=' ')
		print(n + 1, end=' ')
	else:
		for x in range(n - 1):
			if a[x] == 0 and a[x + 1] == 1:
				to_move = x + 1
				break
		if to_move == -1:
			print(-1, end=' ')
		else:
			for x in range(1, to_move + 1):
				print(x, end=' ')
			print(n + 1, end=' ')
			for x in range(to_move + 1, n + 1):
				print(x, end=' ')
t = int(input())
for _ in range(t):
	solve()
	print()


import sys
input = sys.stdin.buffer.readline

def process(A):
	n = len(A)
	last = None
	for i in range(n):
		if A[i] == 0:
			last = i + 1
	if last is None:
		answer = [n + 1]
		for i in range(n):
			answer.append(i + 1)
		return [True, answer]
	answer = []
	for i in range(last):
		answer.append(i + 1)
	answer.append(n + 1)
	for i in range(last, n):
		answer.append(i + 1)
	return [True, answer]
t = int(input())
for i in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	(a1, a2) = process(A)
	if a1:
		print(' '.join(map(str, a2)))
	else:
		print(-1)


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	alst = list(map(int, input().split()))
	if alst[0] == 1:
		print(*[n + 1] + list(range(1, n + 1)))
	else:
		alst.append(1)
		for i in range(n):
			if alst[i] == 0 and alst[i + 1] == 1:
				print(*list(range(1, i + 2)) + [n + 1] + list(range(i + 2, n + 1)))
				return
for _ in range(int(input())):
	main()


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	if A[-1] == 0:
		ans = list(range(1, n + 2))
		print(*ans)
		continue
	if A[0] == 1:
		ans = [n + 1] + list(range(1, n + 1))
		print(*ans)
		continue
	for i in range(n - 1):
		if A[i] == 0 and A[i + 1] == 1:
			p = i
			break
	else:
		print(-1)
		continue
	ans = list(range(p + 1)) + [n] + list(range(p + 1, n))
	ans = [v + 1 for v in ans]
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	lst = [int(el) for el in input().split()]
	ans = []
	if sum(lst) == 0:
		ans = [i for i in range(1, n + 2)]
		print(*ans)
	else:
		i = 0
		while lst[i] != 1:
			i += 1
		if i == 0:
			ans = [n + 1]
			ans += [j for j in range(1, n + 1)]
		else:
			ans = [j for j in range(1, i + 1)]
			ans += [n + 1]
			ans += [j for j in range(i + 1, n + 1)]
		print(*ans)


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

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

def LI1():
	return list(map(int1, sys.stdin.readline().split()))

def LLI1(rows_number):
	return [LI1() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline().rstrip()
inf = 10 ** 16
md = 10 ** 9 + 7

def solve():
	n = II()
	aa = LI()
	if aa[0] == 1:
		ans = [n + 1] + list(range(1, n + 1))
	elif aa[-1] == 0:
		ans = list(range(1, n + 2))
	else:
		last = -1
		for i in range(n)[::-1]:
			if aa[i] == 0:
				last = i
				break
		ans = list(range(last + 1)) + [n] + list(range(last + 1, n))
		ans = [a + 1 for a in ans]
	print(*ans)
for testcase in range(II()):
	solve()


import sys
input = sys.stdin.readline

def read_int():
	return int(input())

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

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

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

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

def solution(a):
	n = len(a)
	if a[-1] == 0:
		return list(range(1, n + 2))
	if a[0] == 1:
		return [n + 1] + list(range(1, n + 1))
	else:
		for i in range(n - 1):
			if a[i] == 0 and a[i + 1] == 1:
				return list(range(1, i + 2)) + [n + 1] + list(range(i + 2, n + 1))
	return [-1]
for _ in range(read_int()):
	n = read_int()
	a = intline()
	print_list(solution(a))


import math
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')
for _ in range(int(input())):
	n = int(input())
	arr = list(map(str, input().split()))
	s = ''.join(arr)
	arr2 = [j for j in range(1, n + 1)]
	if arr[0] == '1':
		print(n + 1, *arr2)
	elif arr[-1] == '0':
		print(*arr2, n + 1)
	else:
		z = s.index('01')
		print(*arr2[:z + 1], n + 1, *arr2[z + 1:])


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	if all((i == 1 for i in a)):
		result = [n + 1] + [i for i in range(1, n + 1)]
	else:
		result = [0] * (n + 1)
		c = False
		for i in range(n - 1, -1, -1):
			if a[i] == 0:
				result[i + 1] = n + 1
				result[i + 2:] = list(range(i + 2, n + 1))
				break
		result[:i + 1] = list(range(1, i + 2))
	for i in result:
		print(i, end=' ')
	print()


t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().split()))
	if a[n - 1] == 0:
		print(*range(1, n + 2))
	elif a.count(0) == 0:
		arr = [n + 1] + [i + 1 for i in range(n)]
		print(*arr)
	else:
		flag = False
		for i in range(n):
			if a[i] == 0:
				flag = True
			elif flag and a[i] == 1:
				index = i
				break
		ans = [i + 1 for i in range(index)] + [n + 1] + [i + 1 for i in range(index, n)]
		print(*ans)
	t -= 1


from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from math import ceil, floor, log, gcd
from collections import Counter, deque
from heapq import heappush, heappop, heapify
from operator import mul
from functools import reduce

class Dsu:

	def __init__(self, n):
		self.groups = n
		self.parent = list(range(n))
		self.size = [1] * n

	def find(self, x):
		tmp = x
		while tmp != self.parent[tmp]:
			self.parent[tmp] = self.parent[self.parent[tmp]]
			tmp = self.parent[tmp]
		return tmp

	def uni(self, x, y):
		(px, py) = (self.find(x), self.find(y))
		if px == py:
			return
		if self.size[py] > self.size[px]:
			(px, py) = (py, px)
		self.parent[py] = px
		self.size[px] += self.size[py]
		self.groups -= 1

	def get_size(self, x):
		return self.size[self.find(x)]

def choose(n, r):
	r = min(r, n - r)
	numer = reduce(mul, range(n, n - r, -1), 1)
	denom = reduce(mul, range(1, r + 1), 1)
	return numer // denom

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

def ints():
	return map(int, re().split())
mod = 1000000007

def solve():
	n = int(re())
	a = list(ints())
	if a[n - 1] == 0:
		print(*list(range(1, n + 2)))
		return
	if a[0] == 1:
		print(*[n + 1] + list(range(1, n + 1)))
		return
	if a[0] == 0:
		for i in range(n - 1):
			if a[i] == 0 and a[i + 1] == 1:
				a = list(range(1, i + 2)) + [n + 1] + list(range(i + 2, n + 1))
				print(*a)
				return
	print(-1)
for t in range(int(re())):
	solve()


for iii in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	if n == 1:
		if lst[0] == 1:
			print(2, 1)
		else:
			print(1, 2)
		continue
	if lst[-1] == 0:
		for i in range(n + 1):
			print(i + 1, end=' ')
		print()
		continue
	tmp = -1
	for i in range(n - 1):
		if lst[i] == 0 and lst[i + 1] == 1:
			tmp = i
			break
	if tmp != -1:
		for i in range(n):
			print(i + 1, end=' ')
			if i == tmp:
				print(n + 1, end=' ')
		print()
		continue
	if sum(lst) == n:
		print(n + 1, end=' ')
		for i in range(n):
			print(i + 1, end=' ')
		print()
		continue
	print(-1)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, vals, ans) = (int(input()), [int(i) for i in input().split()], [])
	if set(vals) == {0}:
		ans = [i + 1 for i in range(n + 1)]
	else:
		for i in range(1, n + 1):
			if vals[i - 1] == 0:
				ans.append(i)
			else:
				ans.extend([n + 1, i])
				break
		for i in range(i, n):
			ans.append(i + 1)
	print(*ans)


from sys import *
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
for _ in range(int(input())):
	n = int(input())
	arr = str_arr()
	st = ''.join(arr)
	lst = []
	if '01' in st or arr[-1] == '0' or arr[0] == '1':
		if arr[-1] == '0':
			lst = [i for i in range(1, n + 2)]
		elif arr[0] == '1':
			lst += [n + 1]
			for i in range(1, n + 1):
				lst += [i]
		elif '01' in st:
			ind = st.index('01')
			for i in range(ind + 1):
				lst += [i + 1]
			lst += [n + 1]
			for i in range(ind + 1, n):
				lst += [i + 1]
		else:
			lst = [-1]
	else:
		lst = [-1]
	print(*lst)


def function(A):
	n = len(A)
	res = []
	if A[0] == 1:
		res = [n + 1] + list(range(1, n + 1))
		return res
	if A[-1] == 0:
		res = list(range(1, n + 1)) + [n + 1]
		return res
	if 1 in A:
		idx = A.index(1)
		res = res + list(range(1, idx + 1)) + [n + 1] + list(range(idx + 1, n + 1))
	else:
		res = list(range(1, n)) + [n + 1, n]
	return res
t = int(input())
for test in range(t):
	n = int(input())
	A = [int(j) for j in input().split()][:n]
	ans = function(A)
	for i in ans:
		print(i, '', end='')
	print()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(range(1, n + 1))
	for i in range(n + 1):
		if i == n or a[n - i - 1] == 0:
			break
	b.insert(n - i, n + 1)
	print(*b)


import sys, os, io

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')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 999999999999999999999999
alphabets = 'abcdefghijklmnopqrstuvwxyz'

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class SegTree:

	def __init__(self, n):
		self.N = 1 << n.bit_length()
		self.tree = [0] * (self.N << 1)

	def update(self, i, j, v):
		i += self.N
		j += self.N
		while i <= j:
			if i % 2 == 1:
				self.tree[i] += v
			if j % 2 == 0:
				self.tree[j] += v
			(i, j) = (i + 1 >> 1, j - 1 >> 1)

	def query(self, i):
		v = 0
		i += self.N
		while i > 0:
			v += self.tree[i]
			i >>= 1
		return v

def SieveOfEratosthenes(limit):
	isPrime = [True] * (limit + 1)
	isPrime[0] = isPrime[1] = False
	primes = []
	for i in range(2, limit + 1):
		if not isPrime[i]:
			continue
		primes += [i]
		for j in range(i * i, limit + 1, i):
			isPrime[j] = False
	return primes
from collections import Counter

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def memodict(f):

	class memodict(dict):

		def __missing__(self, key):
			ret = self[key] = f(key)
			return ret
	return memodict().__getitem__

def pollard_rho(n):
	if n & 1 == 0:
		return 2
	if n % 3 == 0:
		return 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			prev = p
			p = p * p % n
			if p == 1:
				return gcd(prev - 1, n)
			if p == n - 1:
				break
		else:
			for i in range(2, n):
				(x, y) = (i, (i * i + 1) % n)
				f = gcd(abs(x - y), n)
				while f == 1:
					(x, y) = ((x * x + 1) % n, (y * y + 1) % n)
					y = (y * y + 1) % n
					f = gcd(abs(x - y), n)
				if f != n:
					return f
	return n

@memodict
def prime_factors(n):
	if n <= 1:
		return Counter()
	f = pollard_rho(n)
	return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)

def distinct_factors(n):
	factors = [1]
	for (p, exp) in prime_factors(n).items():
		factors += [p ** i * factor for factor in factors for i in range(1, exp + 1)]
	return factors

def all_factors(n):
	(small, large) = ([], [])
	for i in range(1, int(n ** 0.5) + 1, 2 if n & 1 else 1):
		if not n % i:
			small.append(i)
			large.append(n // i)
	if small[-1] == large[-1]:
		large.pop()
	large.reverse()
	small.extend(large)
	return small
	return ans

def main():
	mod = 1000000007
	mod1 = 998244353
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	pow2 = [1]
	for i in range(300005):
		pow2.append(pow2[-1] * 2 % mod1)
	tc = ri()
	for _ in range(tc):
		n = ri()
		a = [-1] + ria()
		ans = []
		if a[1]:
			ans = [n + 1]
			for i in range(1, n + 1):
				ans.append(i)
			wia(ans)
		elif a[-1] == 0:
			for i in range(1, n + 2):
				ans.append(i)
			wia(ans)
		else:
			flag = 0
			for i in range(1, n):
				if a[i] == 0 and a[i + 1]:
					for j in range(1, i + 1):
						ans.append(j)
					ans.append(n + 1)
					for j in range(i + 1, n + 1):
						ans.append(j)
					flag = 1
					break
			if flag:
				wia(ans)
			else:
				wi(-1)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


t = int(input())
for i in range(t):
	n = int(input())
	lst = list(map(int, input().split()))
	ans = []
	for j in range(1, n + 1):
		ans.append(j)
	ind = -1
	for k in range(0, n + 1):
		if k == 0:
			if lst[0] == 1:
				ind = 0
				break
		elif k == n:
			if lst[k - 1] == 0:
				ind = k
				break
		else:
			prev = lst[k - 1]
			next = lst[k]
			if prev == 0 and next == 1:
				ind = k
				break
	if ind == -1:
		print(-1)
	else:
		ans.insert(ind, n + 1)
		print(*ans)


import sys
from os import path
if path.exists('Input.txt'):
	sys.stdin = open('Input.txt', 'r')
	sys.stdout = open('Output.txt', 'w')
input = lambda : sys.stdin.readline().rstrip()
from collections import deque

def solve_tc():
	n = int(input())
	s = list(map(int, input().split()))
	ptr = 0
	ans = []
	for i in range(1, n + 1):
		if s[-i] == 0:
			ptr = n + 1 - i
			break
	else:
		a = [n + 1]
		a.extend([i + 1 for i in range(n)])
		return ' '.join(map(str, a))
	for i in range(ptr):
		ans.append(i + 1)
	ans.append(n + 1)
	for i in range(ptr + 1, n + 1):
		ans.append(i)
	return ' '.join(map(str, ans))
t = int(input())
for _ in range(t):
	sys.stdout.write(str(solve_tc()) + '\n')


import os
import sys
from io import BytesIO, IOBase
import math
from collections import Counter

def func(n, array):
	if 1 not in array:
		return ' '.join((str(i) for i in range(1, n + 2)))
	elif 0 not in array:
		return f'{n + 1} ' + ' '.join((str(i) for i in range(1, n + 1)))
	elif array[-1] == 0:
		return ' '.join((str(i) for i in range(1, n + 2)))
	else:
		for (i, val) in enumerate(array[:-1]):
			if array[i] == 0 and array[i + 1] == 1:
				result = list(range(1, i + 2)) + [n + 1] + list(range(i + 2, n + 1))
				return ' '.join((str(i) for i in result))

def main():
	num_test = int(parse_input())
	result = []
	for _ in range(num_test):
		n = int(parse_input())
		array = [int(i) for i in parse_input().split()]
		result.append(func(n, array))
	print('\n'.join(map(str, result)))
parse_input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	ls = list(map(int, input().split()))
	p = 0
	for i in range(n):
		if ls[i] == 0:
			p = i + 1
	y = 1
	for i in range(n + 1):
		if i == p:
			print(n + 1, end=' ')
		else:
			print(y, end=' ')
			y += 1


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	lst = []
	flag = 0
	for i in range(1, n + 1):
		if a[i - 1] == 1:
			if flag == 0:
				lst.append(n + 1)
				flag = 1
			lst.append(i)
		else:
			lst.append(i)
	if flag == 0:
		lst.append(n + 1)
	print(*lst)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a[0] == 1:
		print(str(n + 1) + ' ' + ' '.join(map(str, range(1, n + 1))))
	elif a[-1] == 0:
		print(' '.join(map(str, range(1, n + 1))) + ' ' + str(n + 1))
	elif n == 1:
		if a[0] == 0:
			print('1 2')
		else:
			print('2 1')
	else:
		k = -1
		for i in range(1, n):
			if a[i] == 1:
				k = i
				break
		print(' '.join(map(str, range(1, k + 1))) + ' ' + str(n + 1) + ' ' + ' '.join(map(str, range(k + 1, n + 1))))


import math
import heapq
import string
from collections import deque
from bisect import bisect, bisect_left, bisect_right, insort
import sys
input = sys.stdin.readline
S = lambda : input()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
H = 1000000000 + 7
for _ in range(I()):
	n = I()
	l = L()
	if min(l) == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
	else:
		i = 0
		while i < n and l[i] == 1:
			i += 1
		while i < n and l[i] == 0:
			i += 1
		for j in range(0, i):
			print(j + 1, end=' ')
		print(n + 1, end=' ')
		for j in range(i, n):
			print(j + 1, end=' ')
		print()


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if 1 not in a:
		print(*list(range(1, n + 2)))
	elif 0 not in a:
		print(*[n + 1] + list(range(1, n + 1)))
	else:
		for i in range(n - 2, -1, -1):
			if a[i] == 0 and a[i + 1] == 1:
				print(*list(range(1, i + 2)) + [n + 1] + list(range(i + 2, n + 1)))
				break
		else:
			print(*[n + 1] + list(range(1, n + 1)))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	flag = False
	idx = -1
	for i in range(n - 1):
		if a[i] == 0 and a[i + 1] == 1:
			flag = True
			idx = i + 1
			break
	if flag:
		for i in range(1, idx + 1):
			print(i, end=' ')
		print(n + 1, end=' ')
		for i in range(idx + 1, n + 1):
			print(i, end=' ')
	elif a[0] == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
	elif a[-1] == 0:
		for i in range(1, n + 1):
			print(i, end=' ')
		print(n + 1, end=' ')
	else:
		print(-1, end=' ')
	print('')


def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	if arr[-1] == 0:
		for i in range(1, n + 2):
			print(i, end=' ')
		print()
		return
	if arr[0] == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
		return
	t_idx = -1
	for i in range(n - 1):
		if arr[i] == 0 and arr[i + 1] == 1:
			t_idx = i
			break
	if t_idx == -1:
		print('-1')
		return
	ans = []
	for i in range(n):
		if i == t_idx:
			ans.append(i)
			ans.append(n)
		else:
			ans.append(i)
	for item in ans:
		print(item + 1, end=' ')
	print()
T = int(input())
for _ in range(T):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n + 1):
		if (i == n or a[i]) and (i == 0 or not a[i - 1]):
			for j in range(n + 1):
				if i == j:
					print(n + 1, end=' ')
				if j < n:
					print(j + 1, end=' ')
			print()
			break
	else:
		print(-1)


import sys
import getpass
import math, random
import functools, itertools, collections, heapq, bisect
from collections import Counter, defaultdict, deque
input = sys.stdin.readline
M9 = 10 ** 9 + 7
(yes, no) = ('YES', 'NO')
MAXINT = sys.maxsize
OFFLINE_TEST = getpass.getuser() == 'hkmac'

def log(*args):
	if OFFLINE_TEST:
		print('\x1b[36m', *args, '\x1b[0m', file=sys.stderr)

def solve(*args):
	if OFFLINE_TEST:
		log('----- solving ------')
		log(*args)
		log('----- ------- ------')
	return solve_(*args)

def read_matrix(rows):
	return [list(map(int, input().split())) for _ in range(rows)]

def read_strings(rows):
	return [input().strip() for _ in range(rows)]

def minus_one(arr):
	return [x - 1 for x in arr]

def minus_one_matrix(mrr):
	return [[x - 1 for x in row] for row in mrr]

def solve_(lst, k):
	if lst[0] == 1:
		return [k + 1] + list(range(1, k + 1))
	if lst[-1] == 0:
		return list(range(1, k + 2))
	for (i, (a, b)) in enumerate(zip(lst, lst[1:]), start=1):
		if a == 0 and b == 1:
			return list(range(1, i + 1)) + [k + 1] + list(range(i + 1, k + 1))
	return [-1]
for case_num in range(int(input())):
	k = int(input())
	lst = list(map(int, input().split()))
	res = solve(lst, k)
	res = ' '.join((str(x) for x in res))
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	for i in range(n - 1):
		if arr[i] == 0 and arr[i + 1] == 1:
			ans = list(range(1, i + 2)) + [n + 1] + list(range(i + 2, n + 1))
			print(' '.join(list(map(str, ans))))
			break
	else:
		if arr[0] == 1:
			ans = [n + 1] + list(range(1, n + 1))
			print(' '.join(list(map(str, ans))))
		elif arr[-1] == 0:
			ans = list(range(1, n + 1)) + [n + 1]
			print(' '.join(list(map(str, ans))))
		else:
			print(-1)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if a[-1] == 0:
		print(*[i for i in range(1, n + 2)])
	elif a[0] == 1:
		print(n + 1, *[i for i in range(1, n + 1)])
	else:
		ans = []
		found = False
		for i in range(1, n):
			ans.append(i)
			if a[i] == 1 and a[i - 1] == 0 and (not found):
				ans.append(n + 1)
				found = True
		ans.append(n)
		if not found:
			print(-1)
		else:
			print(*ans)


for _ in range(int(input())):
	n = int(input())
	arr = (*map(int, input().split()),)
	if arr[0]:
		print(' '.join((str(i % (n + 1) + 1) for i in range(-1, n))))
	elif not arr[-1]:
		print(' '.join((str(i) for i in range(1, n + 2))))
	else:
		last = None
		for (i, val) in enumerate(arr):
			if last is None:
				last = val
				continue
			if val and (not last):
				index = i
				break
		print(' '.join((str(i) for i in range(1, index + 1))), end=' ')
		print(n + 1, end=' ')
		print(' '.join((str(i) for i in range(index + 1, n + 1))))


from sys import stdin
input = stdin.readline
rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input().strip()
YN = lambda x: print('YES') if x else print('NO')
mod = 10 ** 9 + 7
for _ in range(rn()):
	n = rn()
	a = rl()
	if a[-1] == 0:
		print(*list(range(1, n + 2)))
	elif a[0] == 1:
		print(*[n + 1] + list(range(1, n + 1)))
	elif sum(a) == n:
		print(-1)
	else:
		ans = list(range(1, n + 1))
		for i in range(1, n):
			if a[i] and (not a[i - 1]):
				ans.insert(i, n + 1)
				break
		print(*ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	if l[0] == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
	elif l[n - 1] == 0:
		for i in range(1, n + 1):
			print(i, end=' ')
		print(n + 1)
	else:
		(a, b) = (0, 0)
		for i in range(n - 1):
			if l[i] == 0 and l[i + 1] == 1:
				a = i + 1
				b = i + 2
		for i in range(1, a + 1):
			print(i, end=' ')
		print(n + 1, end=' ')
		for i in range(b, n + 1):
			print(i, end=' ')
		print()


import re

def plot(b, n):
	m1 = re.search('01', b)
	if m1:
		return list(range(1, m1.span()[0] + 2)) + [n + 1] + list(range(m1.span()[0] + 2, n + 1))
	m1 = re.search('1', b)
	if m1:
		return [n + 1] + list(range(1, n + 1))
	return list(range(1, n + 2))
z = int(input())
for _ in range(z):
	n = int(input())
	a = re.split(' +', input())
	assert len(a) == n
	assert not set(a) - {'0', '1'}
	b = ''.join(a)
	l = plot(b, n)
	print(' '.join((str(i) for i in l)))


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

def dbg(*args, **kwargs):
	_print('\x1b[95m', end='')
	_print(*args, **kwargs)
	_print('\x1b[0m', end='')

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 inp():
	return sys.stdin.readline().rstrip()

def mpint():
	return map(int, inp().split(' '))

def itg():
	return int(inp())

def gen_the_other(data):
	(a, b) = data[:2]

	def other(x):
		return a if x == b else b
	return other
other = gen_the_other('BR')

def solve():
	n = itg()
	arr = list(mpint())
	if arr[0]:
		return [n + 1] + list(range(1, n + 1))
	if arr[-1] == 0:
		return range(1, n + 2)
	arr = [0] + arr
	i = 1
	b = False
	ans = []
	while i <= n:
		ans.append(i)
		if not b and arr[i] == 0 and (i + 1 < n) and (arr[i + 1] == 1):
			ans.append(n + 1)
			b = True
		i += 1
	if not b:
		del ans[-1]
		ans.append(n + 1)
		ans.append(n)
	return ans

def main():
	for _ in range(itg()):
		print(*solve())
DEBUG = 0
URL = 'https://codeforces.com/contest/1559/problem/C'
if DEBUG == 1:
	import requests
	from ACgenerator.Y_Test_Case_Runner import TestCaseRunner
	runner = TestCaseRunner(main, URL)
	inp = runner.input_stream
	print = runner.output_stream
	runner.checking()
else:
	if DEBUG != 2:
		dbg = lambda *args, **kwargs: ...
		(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	if DEBUG == 3:

		def print(*args, **kwargs):
			_print(*args, **kwargs)
			sys.stdout.flush()
	main()


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(j) for j in input().split()]
	if arr[-1] == 0:
		ans = [i for i in range(1, n + 2)]
		print(*ans)
		continue
	if arr[0] == 1:
		ans = [n + 1] + [i for i in range(1, n + 1)]
		print(*ans)
		continue
	ind = -1
	for i in range(n - 1):
		if arr[i] == 0 and arr[i + 1] == 1:
			ind = i
			break
	assert ind != -1
	ans = []
	for i in range(ind + 1):
		ans += [i]
	ans += [n]
	for i in range(ind + 1, n):
		ans += [i]
	for i in range(len(ans)):
		ans[i] += 1
	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')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		if a[0] == 0:
			print(1, 2)
		else:
			print(2, 1)
		continue
	if a[-1] == 0:
		print(*[i for i in range(1, n + 2)])
		continue
	else:
		ind = None
		for i in range(n - 1):
			if a[i] == 0 and a[i + 1] == 1:
				ind = i
				break
		if a[0] == 1:
			print(n + 1)
			for i in range(1, n + 1):
				print(i, end=' ')
			print()
		else:
			ans = []
			for i in range(1, ind + 2):
				ans.append(i)
			ans.append(n + 1)
			for i in range(ind + 2, n + 1):
				ans.append(i)
			print(*ans)


import sys

def solve(arr):
	n = len(arr)
	if arr[0] == 1:
		answer = [n + 1] + [i + 1 for i in range(n)]
		return ' '.join((str(i) for i in answer))
	if arr[-1] == 0:
		answer = [i + 1 for i in range(n + 1)]
		return ' '.join((str(i) for i in answer))
	prev = None
	found = -1
	for (i, cur) in enumerate(arr):
		if cur == 1 and prev == 0:
			found = i
			break
		prev = cur
	if found == -1:
		return -1
	answer = [i + 1 for i in range(found)] + [n + 1] + [i + 1 for i in range(found, n)]
	return ' '.join((str(i) for i in answer))

def main():
	outputs = []
	fin = sys.stdin
	N = int(fin.readline())
	for _ in range(N):
		n = int(fin.readline())
		arr = list(map(int, fin.readline().split()))
		outputs.append(solve(arr))
	print('\n'.join(map(str, outputs)))
main()


def solve(n, arr):
	check = False
	if arr[0] == 1:
		print(n + 1, end=' ')
		print(*list(range(1, n + 1)), sep=' ')
		return
	elif arr[n - 1] == 0:
		print(*list(range(1, n + 1)), sep=' ', end=' ')
		print(n + 1)
		return
	else:
		for x in range(1, n):
			if arr[x] == 1 and arr[x - 1] == 0:
				rem = x - 1
				check = True
				break
	if check:
		for i in range(n):
			print(i + 1, end=' ')
			if i == rem:
				print(n + 1, end=' ')
		return
	else:
		print(-1)
for _ in range(int(input())):
	solve(int(input()), list(map(int, input().split())))


_ = 1
_ = int(input())
while _ > 0:
	_ -= 1
	n = int(input())
	l = list(map(int, input().split()))
	if n == 1:
		if l[0] == 0:
			print('1 2')
		else:
			print('2 1')
		continue
	if l[0] == 1:
		print(n + 1, end=' ')
		print(*[x for x in range(1, n + 1)])
		continue
	if l[-1] == 0:
		print(*[x for x in range(1, n + 2)])
		continue
	for x in range(n - 1):
		if l[x] == 0 and l[x + 1] == 1:
			index = x + 1
			break
	print(*[x for x in range(1, index + 1)], end=' ')
	print(n + 1, end=' ')
	print(*[x for x in range(index + 1, n + 1)])


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	if a[0] != 0:
		print(n + 1, end=' ')
		for j in range(1, n + 1):
			print(j, end=' ')
		print()
	elif a[-1] == 0:
		for j in range(1, n + 2):
			print(j, end=' ')
		print()
	else:
		fl = 0
		for j in range(1, n):
			if a[j] == 1 and a[j - 1] == 0:
				fl = 1
				break
		else:
			print(-1)
		if fl:
			fl = 0
			print('1', end=' ')
			for j in range(1, n):
				if fl == 0 and a[j] == 1 and (a[j - 1] == 0):
					print(n + 1, end=' ')
					print(j + 1, end=' ')
					fl = 1
				else:
					print(j + 1, end=' ')
			print()


for _ in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	if nums[0]:
		ans = [n + 1] + list(range(1, n + 1))
	elif not nums[-1]:
		ans = list(range(1, n + 2))
	else:
		ans = []
		for i in range(n):
			ans.append(i + 1)
			if nums[i + 1] and (not nums[i]):
				ans.append(n + 1)
				ans.extend(list(range(i + 2, n + 1)))
				break
	print(' '.join(map(str, ans)))


import sys
import math
import heapq
from collections import defaultdict as dd
from collections import OrderedDict as od
from collections import deque
from itertools import permutations as pp
from itertools import combinations as cc
from sys import stdin
from functools import cmp_to_key
from functools import lru_cache
from bisect import bisect_left as bs_l
from bisect import bisect_right as bs_r
input = sys.stdin.readline
mod = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 5)
T = int(input())
for _ in range(T):
	n = int(input())
	ll = list(map(int, input().split()))
	if ll[0]:
		ans = [n + 1]
		for i in range(1, n + 1):
			ans.append(i)
		print(*ans)
	elif ll[n - 1] == 0:
		ans = []
		for i in range(1, n + 2):
			ans.append(i)
		print(*ans)
	else:
		f = -1
		for i in range(n - 1):
			if ll[i] == 0 and ll[i + 1]:
				f = i + 1
				break
		if f == -1:
			print(-1)
		else:
			ans = []
			for i in range(1, f + 1):
				ans.append(i)
			ans.append(n + 1)
			for i in range(f + 1, n + 1):
				ans.append(i)
			print(*ans)


import math

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	det = -1
	for i in range(n - 1, -1, -1):
		if a[i] == 0:
			det = i
			break
	if det == -1:
		print(n + 1, end=' ')
	for i in range(n):
		print(i + 1, end=' ')
		if i == det:
			print(n + 1, end=' ')
	print()
for _ in range(int(input())):
	solve()


t = int(input())
results = []
for i in range(t):
	n = int(input())
	nums = [int(num) for num in input().split()]
	if nums[0] == 1:
		results.append(' '.join([str(n + 1)] + [str(j) for j in range(1, n + 1)]))
	elif nums[-1] == 0:
		results.append(' '.join([str(j) for j in range(1, n + 2)]))
	else:
		for j in range(n - 1):
			if nums[j] == 0 and nums[j + 1] != 0:
				path = [str(x) for x in range(1, j + 2)] + [str(n + 1)] + [str(x) for x in range(j + 2, n + 1)]
				results.append(' '.join(path))
				break
		else:
			results.append('-1')
for i in range(t):
	print(results[i])


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if n == 1:
		if arr[0] == 0:
			print(1, 2)
		else:
			print(2, 1)
	elif arr[0] == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
	elif arr[-1] == 0:
		for i in range(1, n + 1):
			print(i, end=' ')
		print(n + 1, end=' ')
	else:
		can = False
		ind = -1
		for i in range(n):
			if arr[i] == 0:
				if i + 1 < n and arr[i + 1] == 1:
					ind = i
					can = True
			continue
		if can == False:
			print(-1)
		else:
			ind += 1
			for i in range(1, ind + 1):
				print(i, end=' ')
			print(n + 1, end=' ')
			for i in range(ind + 1, n + 1):
				print(i, end=' ')
			print()


def solution():
	l = int(input())
	n = input()
	ar = n.split()
	ar.reverse()
	ans = [i + 1 for i in range(l)]
	temp = int(l)
	for i in ar:
		if i == '0':
			break
		temp -= 1
	ans.insert(temp, l + 1)
	for j in ans:
		print(j, end=' ')
	print('')
	return
	print(-1)
t = int(input())
while t > 0:
	t -= 1
	solution()


for i in range(int(input())):
	inten = lambda x: int(x)
	n = int(input())
	array = input().split(' ')
	array = list(map(inten, array))
	if array[-1] == 0:
		print(', '.join([str(i + 1) for i in range(len(array) + 1)]).replace(',', ''))
	elif 1 in array:
		davor_zu_n = True
		zuruck_zu_x = False
		for (counter, i) in enumerate(array):
			if i == 1 and davor_zu_n:
				str_1 = ', '.join([str(i + 1) for i in range(counter)]).replace(',', '')
				str_2 = ', '.join([str(i + 1) for i in range(counter, n)]).replace(',', '')
				if str_1 == '':
					print(str(n + 1) + ' ' + str_2)
				elif str_2 == '':
					print(str_1 + ' ' + str(n + 1))
				else:
					print(str_1 + ' ' + str(n + 1) + ' ' + str_2)
				break
			elif i == 1:
				davor_zu_n = False
			elif i == 0:
				davor_zu_n = True
	else:
		print('-1')


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

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

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return [int(x) for x in input().split()]
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	n = int(input())
	ll = mapin()
	fl = -1
	for i in range(n - 1):
		if ll[i] == 0 and ll[i + 1] == 1:
			fl = i + 1
			break
	if ll[0] == 1:
		fl = 0
	if ll[-1] == 0:
		fl = n
	if fl == -1:
		print(fl)
	else:
		l = []
		for i in range(fl):
			l.append(i + 1)
		l.append(n + 1)
		for i in range(n - fl):
			l.append(fl + i + 1)
		print(*l)


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

def lcm(a, b):
	return a / gcd(a, b) * b
mini = 100000
tests = int(input())
mod = 10 ** 9 + 7
while tests:
	tests -= 1
	n = int(input())
	arr = list(map(int, input().split()))
	ans = ''
	if arr[-1] == 0:
		for i in range(n + 1):
			ans += str(i + 1) + ' '
	elif arr[0] == 1:
		ans = str(n + 1) + ' '
		for i in range(n):
			ans += str(i + 1) + ' '
	else:
		done = False
		for i in range(n):
			ans += str(i + 1) + ' '
			if not done and arr[i] == 0 and (i + 1 < n and arr[i + 1] == 1):
				ans += str(n + 1) + ' '
				done = True
		if not done:
			ans = -1
	print(ans)


import sys
from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
ANS = []
input = stdin.readline

def solve():
	pass
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr[-1] == 0:
		for i in range(n + 1):
			print(i + 1, end=' ')
		print()
		continue
	elif arr[0] == 1:
		print(n + 1, end=' ')
		for i in range(n):
			print(i + 1, end=' ')
		print()
	else:
		f = 0
		for i in range(n - 1):
			if arr[i] == 0 and arr[i + 1] == 1:
				f = 1
				for j in range(i):
					print(j + 1, end=' ')
				print(i + 1, end=' ')
				print(n + 1, end=' ')
				print(i + 2, end=' ')
				for j in range(i + 2, n):
					print(j + 1, end=' ')
				print()
				break
		if f == 0:
			print(-1)
print('\n'.join(ANS))


def solve(arr, n):
	first = n + 1
	for i in range(1, n + 1):
		if arr[i] != 0:
			first = i
			break
	if first != n + 1:
		for i in range(1, first):
			print(i, end=' ')
		print(n + 1, end=' ')
		for i in range(first, n + 1):
			print(i, end=' ')
		print()
	else:
		for i in range(1, n + 2):
			print(i, end=' ')
for _ in range(int(input())):
	n = int(input())
	arr = [0] + list(map(int, input().split()))
	solve(arr, n)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	l = 0
	flag = False
	if a[0] == 1:
		print(n + 1, *list(range(1, n + 1)))
	else:
		while flag == False:
			l += 1
			if l == n:
				print(*list(range(1, n + 2)))
				flag = True
			elif a[l] == 1:
				print(*list(range(1, l + 1)), n + 1, *list(range(l + 1, n + 1)))
				flag = True


def solve():
	n = int(input())
	arr = [0] + [int(x) for x in input().split()]
	path = []
	if n == 1:
		if arr[1] == 1:
			return '2 1'
		return '1 2'
	if arr[1] == 1:
		path.append(n + 1)
		path.extend(range(1, 1 + n))
	elif arr[n] == 0:
		path.extend(range(1, 2 + n))
	else:
		for i in range(1, n):
			if arr[i] == 0 and arr[i + 1] == 1:
				path.extend(range(1, i + 1))
				path.append(n + 1)
				path.extend(range(i + 1, n + 1))
				break
	if path:
		return ' '.join((str(x) for x in path))
	return -1
for _ in range(int(input())):
	print(solve())


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))[:n]
	if ar[-1] == 0:
		for i in range(1, n + 2):
			print(i, end=' ')
		print()
	else:
		k = ar.index(1)
		b = []
		for i in range(k):
			b.append(i + 1)
		b.append(n + 1)
		for j in range(k + 1, n + 1):
			b.append(j)
		print(*b)


def findAns(n, arr):
	res = [i for i in range(1, n + 1)]
	if arr[0] == 1:
		return [n + 1] + res
	if arr[-1] == 0:
		return res + [n + 1]
	for x in range(len(arr) - 1):
		if arr[x] == 0 and arr[x + 1] == 1:
			return res[:x + 1] + [n + 1] + res[x + 1:]
T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split()))
	res = findAns(n, arr)
	print(' '.join(map(str, res)))


import os
import sys
import math
from io import BytesIO, IOBase

def upperbound(arr, val):
	start = 0
	end = len(arr) - 1
	ans = -1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] <= val:
			start = mid + 1
		else:
			ans = mid
			end = mid - 1
	return ans

def lowerbound(arr, val):
	length = len(arr)
	answer = -1
	start = 0
	end = length - 1
	while start <= end:
		middle = (start + end) // 2
		if arr[middle] == val:
			answer = middle
			end = middle - 1
		elif arr[middle] > val:
			end = middle - 1
		else:
			start = middle + 1
	return answer

def D2B(n):
	arr = []
	while n > 0:
		temp = n
		m = 0
		p = 1
		while temp:
			rem = temp % 10
			temp = int(temp / 10)
			if rem != 0:
				m += p
			p *= 10
		arr.append(m)
		n = n - m
	return arr

def sort2D(arr, axis):
	arr = sorted(arr, key=lambda x: x[axis])
	return arr

def DD(rows, cols):
	arr = [[0 for i in range(cols)] for j in range(rows)]
	return arr
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')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	n = int(input())
	flag = 0
	a = [int(x) for x in input().split()]
	if n == 1:
		if a[0] == 0:
			print(1, 2)
		else:
			print(2, 1)
	elif a.count(0) == n:
		for i in range(1, n + 2):
			print(i, end=' ')
	elif a[-1] == 0:
		for i in range(1, n + 2):
			print(i, end=' ')
	elif a[0] == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
	else:
		for i in range(n - 1):
			if a[i] == 0 and a[i + 1] == 1:
				for j in range(1, i + 2):
					print(j, end=' ')
				print(n + 1, end=' ')
				for k in range(j + 1, n + 1):
					print(k, end=' ')
				break
f = 1
if f == 1:
	t = int(input())
	while t:
		solve()
		t -= 1
else:
	solve()


t = int(input())
for lfkasjflkaj in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	ans = [str(i + 1) for i in range(n)]
	if l[0] == 1:
		print(str(n + 1) + ' ' + ' '.join(ans))
	elif l[-1] == 0:
		print(' '.join(ans) + ' ' + str(n + 1))
	else:
		flag = 0
		for i in range(n - 1):
			if l[i] == 0 and l[i + 1] == 1:
				print(' '.join(ans[:i + 1]) + ' ' + str(n + 1) + ' ' + ' '.join(ans[i + 1:]))
				flag = 1
				break
		if flag == 0:
			print('-1')


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	if a[-1] == 0:
		for i in range(1, n + 2):
			print(i, end=' ')
		continue
	if a[0] == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
		continue
	i = 0
	flag = True
	while i < len(a):
		if a[i] == 0 and a[i + 1] == 1 and flag:
			print(i + 1, n + 1, i + 2, end=' ')
			flag = False
			i += 2
		else:
			print(i + 1, end=' ')
			i += 1


import sys
sys.setrecursionlimit(100000000)
for _ in range(int(input())):
	n = int(input())
	directions = list(map(int, input().split()))
	ans = []
	if directions[-1] == 0:
		ans = [i for i in range(1, n + 2)]
	else:
		i = n - 1
		while i >= 0 and directions[i] != 0:
			i -= 1
		if i == -1:
			ans = [n + 1]
			for j in range(1, n + 1):
				ans.append(j)
		else:
			for j in range(1, i + 2):
				ans.append(j)
			ans.append(n + 1)
			for j in range(i + 2, n + 1):
				ans.append(j)
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	bo = 1
	res = []
	if a[-1] == 0:
		res = [str(i) for i in range(1, n + 2)]
		bo = 0
	elif a[0] == 1:
		res = [str(n + 1), '1']
		res += [str(i) for i in range(2, n + 1)]
		bo = 0
	else:
		res = []
		bo = 1
		for i in range(n):
			if a[i] == 0 and a[i + 1] == 1 and bo:
				res.append(str(i + 1))
				res.append(str(n + 1))
				bo = 0
			else:
				res.append(str(i + 1))
	if bo:
		print(-1)
	else:
		print(' '.join(res))


import sys
from math import gcd, ceil, sqrt
import bisect
INF = float('inf')
MOD = 998244353
mod = 10 ** 9 + 7
from collections import Counter, defaultdict as df
from functools import reduce

def counter(l):
	return dict(Counter(l))

def printm(l):
	for i in range(len(l[0])):
		print(*l[i])

def P(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, ceil(sqrt(n)) + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def so(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def rev(l):
	return list(reversed(l))

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

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

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

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

def inputm(n, m):
	return [li() for i in range(m)]
for _ in range(ini()):
	n = ini()
	l = li()
	if l[0] == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
		continue
	if l[-1] == 0:
		for i in range(1, n + 1):
			print(i, end=' ')
		print(n + 1)
		continue
	c = -1
	for i in range(1, n):
		if l[i] != l[i - 1] and l[i - 1] == 0:
			c = 1
			break
	if c == -1:
		print(c)
	else:
		for j in range(1, i + 1):
			print(j, end=' ')
		print(n + 1, end=' ')
		for j in range(i + 1, n + 1):
			print(j, end=' ')
		print()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	if arr[0] == 1:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
		continue
	if arr[-1] == 0:
		for i in range(1, n + 2):
			print(i, end=' ')
		print()
		continue
	flag = 0
	for i in range(n - 1):
		print(i + 1, end=' ')
		if arr[i] == 0 and arr[i + 1] == 1:
			print(n + 1, end=' ')
			for j in range(i + 2, n + 1):
				print(j, end=' ')
			flag = 1
			break
	if flag == 0:
		print(-1)
	print()


from sys import stdin
inp = stdin.readline
t = int(inp())
for _ in range(t):
	n = int(inp())
	a = [int(x) for x in inp().split()]
	out = [0 for x in range(n + 1)]
	zero = False
	for i in range(n):
		if not zero:
			if a[n - i - 1] == 0:
				zero = True
				out[n - i] = n + 1
				out[n - i - 1] = n - i
			else:
				out[n - i] = n - i
		else:
			out[n - i - 1] = n - i
	if not zero:
		out[0] = n + 1
	print(*out)


import os, sys
from io import BytesIO, IOBase
from types import GeneratorType
from bisect import *
from collections import defaultdict, deque, Counter
import math, string
from heapq import *
from operator import add
from itertools import accumulate
BUFSIZE = 8192
sys.setrecursionlimit(10 ** 5)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 = self.os.read(self._fd, max(self.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 = self.os.read(self._fd, max(self.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:
			self.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')
inf = float('inf')
en = lambda x: list(enumerate(x))
ceil_ = lambda a, b: (a + b - 1) // b
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())

def solve():
	n = ii()
	arr = rr()
	f = inf
	if n == 1:
		if arr[0] == 0:
			print(1, 2)
		else:
			print(2, 1)
		return
	for i in range(n - 1):
		if arr[i] == 0 and arr[i + 1] == 1:
			f = i
			break
	if f != inf:
		f += 1
		arr = list(range(1, f + 1)) + [n + 1] + list(range(f + 1, n + 1))
		print(*arr)
	elif arr[-1] == 0 and arr[0] == 1:
		arr = [n, n + 1] + list(range(1, n))
		print(*arr)
	elif not arr[-1]:
		print(*range(1, n + 2))
	elif arr[0] == 1:
		print(n + 1, *range(1, n + 1))
	else:
		print(-1)
for _ in ' ' * ii():
	solve()


import sys
input = sys.stdin.readline

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

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

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

def ma():
	return map(int, input().split())
t = inp()
gl = {'R': 'B', 'B': 'R'}
while t:
	t -= 1
	n = inp()
	a = lis()
	if a[-1] == 0:
		print(*[i for i in range(1, n + 2)])
		continue
	elif a[0] == 1:
		print(n + 1, end=' ')
		print(*[i for i in range(1, n + 1)])
	else:
		have = 1
		for i in range(n):
			if a[i] == 0:
				print(have, end=' ')
				have += 1
			else:
				print(n + 1, end=' ')
				print(*[i for i in range(have, n + 1)])
				break


T = int(input())
for t in range(T):
	N = int(input())
	arr = list(map(int, input().split()))
	if arr[0]:
		print(str(N + 1) + ' ' + ' '.join(map(str, range(1, N + 1))))
	elif not arr[-1]:
		print(' '.join(map(str, range(1, N + 2))))
	else:
		for i in range(N - 1):
			if not arr[i] and arr[i + 1]:
				print(' '.join(map(str, range(1, i + 2))) + ' ' + str(N + 1) + ' ' + ' '.join(map(str, range(i + 2, N + 1))))
				break
		else:
			print(-1)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		adj = [[] for i in range(n + 1)]
		a = list(map(int, input().split()))
		for i in range(n - 1):
			adj[i].append(i + 1)
		for (i, x) in enumerate(a):
			if x == 0:
				adj[i].append(n)
			else:
				adj[n].append(i)
		(res, found) = ([], [0] * len(adj))
		stack = list(range(len(adj)))
		while stack:
			node = stack.pop()
			if node < 0:
				res.append(~node)
			elif not found[node]:
				found[node] = 1
				stack.append(~node)
				stack += adj[node]
		print(*map(lambda x: x + 1, res[::-1]), sep=' ')
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()


def prob():
	n = int(input())
	l = [int(x) for x in input().split()]
	arr = [0] * (n + 1)
	for i in range(1, n + 1):
		arr[i] = l[i - 1]
	ans = [0] * (n + 1)
	fl = 0
	if arr[1] == 1:
		ans[0] = n + 1
		fl = 1
		for i in range(1, n + 1):
			ans[i] = i
	elif arr[n] == 0:
		for i in range(n + 1):
			ans[i] = i + 1
	else:
		fl = 0
		for i in range(1, n):
			ans[i - 1] = i
			if arr[i] == 0 and arr[i + 1] == 1:
				fl = i + 1
				ans[i] = n + 1
				break
		if fl == 0:
			print(-1)
			return
		else:
			while fl <= n:
				ans[fl] = fl
				fl += 1
	print(*ans)
t = 1
t = int(input())
for _ in range(0, t):
	prob()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if a[-1] == 0:
		ans = range(1, n + 2)
		print(*ans)
		continue
	elif a[0] != 0:
		ans = [n + 1]
		ans += list(range(1, n + 1))
		print(*ans)
	else:
		r = -1
		for i in range(0, n - 1):
			if a[i] == 0 and a[i + 1] != 0:
				r = i
				break
		ans = list(range(1, r + 2))
		ans.append(n + 1)
		ans += range(r + 2, n + 1)
		print(*ans)


from sys import stdin, stdout
input = stdin.readline

def solution(a):
	n = len(a)
	if a[-1] == 0:
		return list(range(1, n + 2))
	if a[0] == 1:
		return [n + 1] + list(range(1, n + 1))
	else:
		for i in range(n - 1):
			if a[i] == 0 and a[i + 1] == 1:
				return list(range(1, i + 2)) + [n + 1] + list(range(i + 2, n + 1))
	return [-1]
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	print(*solution(a))


T = int(input())
for _ in range(T):
	n = int(input())
	data = list(map(int, input().split()))
	last = -1
	for i in range(n):
		if data[i] == 0:
			last = i
	for i in range(last + 1):
		print(i + 1, end=' ')
	print(n + 1, end=' ')
	for i in range(last + 1, n):
		print(i + 1, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a[-1] == 0:
		b = list(range(1, n + 2))
		print(*b)
	elif a[0] == 1:
		b = list(range(1, n + 1))
		b = [n + 1] + b
		print(*b)
	else:
		for i in range(n):
			p = 0
			q = 0
			if a[i] == 0 and a[i + 1] == 1:
				p = i + 1
				q = i + 2
				c = list(range(1, p + 1))
				d = list(range(q, n + 1))
				f = c + [n + 1] + d
				print(*f)
				break
		else:
			print(-1)


t = int(input())
for i in range(0, t):
	vertex = int(input())
	vis_list = list(map(int, input().split()))
	cnt = 0
	g = 0
	for k in vis_list:
		if k == 1:
			cnt += 1
		else:
			g += 1
	else:
		road = []
		for x in range(1, vertex + 1):
			road.append(x)
		ind = 0
		for k in vis_list:
			if k == 1:
				road.insert(ind, vertex + 1)
				break
			ind += 1
		if g == vertex:
			road.append(vertex + 1)
		print(*road)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = []
	f = True
	for i in range(len(a)):
		if f and a[i] != 0:
			ans.append(n + 1)
			f = False
		ans.append(i + 1)
	if len(ans) == len(a):
		ans.append(n + 1)
	print(*ans)


from __future__ import division, print_function
from collections import defaultdict
import os
import sys
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

def find_SCC(graph):
	(SCC, S, P) = ([], [], [])
	depth = [0] * len(graph)
	stack = list(range(len(graph)))
	while stack:
		node = stack.pop()
		if node < 0:
			d = depth[~node] - 1
			if P[-1] > d:
				SCC.append(S[d:])
				del S[d:], P[-1]
				for node in SCC[-1]:
					depth[node] = -1
		elif depth[node] > 0:
			while P[-1] > depth[node]:
				P.pop()
		elif depth[node] == 0:
			S.append(node)
			P.append(len(S))
			depth[node] = len(S)
			stack.append(~node)
			stack += graph[node]
	return SCC[::-1]

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		if a[-1] == 0:
			print(*range(1, n + 2))
			continue
		elif a[0] == 1:
			print(*[n + 1] + list(range(1, n + 1)))
			continue
		for i in range(n - 1):
			if a[i] == 0 and a[i + 1] == 1:
				print(*list(range(1, i + 2)) + [n + 1] + list(range(i + 2, n + 1)))
				break
		else:
			print(-1)
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))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if a[-1] == 0:
		print(*[i for i in range(1, n + 2)])
	else:
		res = []
		f = 0
		for i in range(n - 1, 0, -1):
			if a[i - 1] == 0:
				for j in range(1, i + 1):
					res.append(j)
				res.append(n + 1)
				for j in range(i + 1, n + 1):
					res.append(j)
				f = 1
				break
			else:
				pass
		if f == 0:
			print(n + 1, end=' ')
			for i in range(1, n + 1):
				print(i, end=' ')
			print()
		else:
			print(*res)


for _ in range(int(input())):
	n = int(input())
	path = [i for i in range(1, n + 1)]
	ai = input().split()
	for k in range(n):
		ai[k] = int(ai[k])
		ai.append(3)
	for j in range(n):
		if ai[j] == 0 and ai[j + 1] == 1:
			path.insert(j + 1, n + 1)
			print(' '.join([str(x) for x in path]))
			break
		elif ai[n - 1] == 0:
			path.append(n + 1)
			print(' '.join([str(x) for x in path]))
			break
		elif ai[0] == 1:
			path.insert(0, n + 1)
			print(' '.join([str(x) for x in path]))
			break
	if len(path) < n + 1:
		print(-1)


t = int(input())
for j in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	result = [x + 1 for x in range(n)]
	ok = False
	if a[0] == 1:
		print(' '.join(map(str, [n + 1] + result)))
		continue
	if a[-1] == 0:
		print(' '.join(map(str, result + [n + 1])))
		continue
	for i in range(n - 1):
		if (a[i], a[i + 1]) == (0, 1):
			ok = True
			result.insert(i + 1, n + 1)
			break
	if ok:
		print(' '.join(map(str, result)))
	else:
		print(-1)


debug = 0

def solve(n, mas):
	if mas[-1] == 0:
		return ' '.join(map(str, list(range(1, n + 2))))
	if mas[0] == 1:
		return ' '.join(map(str, [n + 1] + list(range(1, n + 1))))
	mas_str = ''.join(map(str, mas))
	if '01' in mas_str:
		ind = mas_str.index('01')
		return ' '.join(map(str, list(range(1, ind + 1)) + [ind + 1] + [n + 1] + list(range(ind + 2, n + 1))))
	return -1
if debug:
	ans = []
	with open('input.txt', 'r') as file:
		for i in range(int(file.readline().strip())):
			ans.append(solve(int(file.readline().strip()), list(map(int, file.readline().strip()))))
	for i in ans:
		print(i)
if not debug:
	for _ in range(int(input())):
		print(solve(int(input()), list(map(int, input().split()))))


from sys import stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
(t,) = rl()
for _ in range(t):
	(n,) = rl()
	a = rl()
	if a[0] == 1:
		print(n + 1, *range(1, n + 1))
	elif a[-1] == 0:
		print(*range(1, n + 2))
	else:
		for i in range(1, n + 1):
			if a[i] == 1:
				print(*range(1, i + 1), n + 1, *range(i + 1, n + 1))
				break


t = int(input())
while t:
	n = int(input())
	V = list(map(int, input().split()))[:n]
	A = []
	if V[0] == 1:
		A.append(n + 1)
		for i in range(n):
			A.append(i + 1)
	elif V[-1] == 0:
		for i in range(n):
			A.append(i + 1)
		A.append(n + 1)
	else:
		for i in range(n - 1):
			if V[i] == 0 and V[i + 1] == 1:
				a = i
		for i in range(n):
			if i != a:
				A.append(i + 1)
			else:
				A.append(i + 1)
				A.append(n + 1)
	print(*A)
	t -= 1


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')

class RangeQuery:

	def __init__(self, data, func=min):
		self.func = func
		self._data = _data = [list(data)]
		(i, n) = (1, len(_data[0]))
		while 2 * i <= n:
			prev = _data[-1]
			_data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)])
			i <<= 1

	def query(self, start, stop):
		depth = (stop - start).bit_length() - 1
		return self.func(self._data[depth][start], self._data[depth][stop - (1 << depth)])

	def __getitem__(self, idx):
		return self._data[0][idx]

def check(st, n, k):
	for i in range(n - k + 1):
		g = st.query(i, i + k)
		if g > 1:
			return True
	return False
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict, deque
from math import ceil, floor, sqrt, log2, gcd, pi
from heapq import heappush, heappop
from fractions import Fraction
from bisect import bisect_left, bisect
import sys
abc = 'abcdefghijklmnopqrstuvwxyz'
ABC = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = []
	if arr[-1] == 0:
		ans = list(range(1, n + 2))
		print(*ans)
	else:
		flag = 0
		val = -1
		for i in range(n - 1):
			if arr[i] == 0 and arr[i + 1] == 1:
				flag = 1
				val = i
				break
		if flag == 0 and arr[0] == 0:
			print(-1)
		elif flag == 0 and arr[0] == 1:
			ans.append(n + 1)
			for i in range(1, n + 1):
				ans.append(i)
			print(*ans)
		else:
			for i in range(1, val + 2):
				ans.append(i)
			ans.append(n + 1)
			for i in range(val + 2, n + 1):
				ans.append(i)
			print(*ans)


for _ in range(int(input())):
	a = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in range(1, a + 2):
		d[i] = []
	for i in range(1, a):
		d[i].append(i + 1)
	for i in range(1, len(l) + 1):
		if l[i - 1] == 0:
			d[i].append(a + 1)
		else:
			d[a + 1].append(i)
	flag = 0
	l2 = []
	flag1 = 0
	for i in range(len(l) - 1):
		if l[i] == 0 and l[i + 1] == 1 and (flag1 == 0):
			flag1 = 1
			l2.append(i + 1)
			l2.append(a + 1)
		else:
			l2.append(i + 1)
	l2.append(a)
	if len(l2) == a + 1:
		flag = 1
		print(*l2)
	elif a + 1 in d[a]:
		flag = 1
		l1 = [i for i in range(1, a + 2)]
		print(*l1)
	elif 1 in d[a + 1]:
		l1 = [a + 1]
		flag = 1
		for i in range(1, a + 1):
			l1.append(i)
		print(*l1)
	if flag == 0:
		print(-1)


import sys
input = sys.stdin.readline
import bisect
from bisect import bisect_left
import math
from collections import defaultdict
from collections import Counter
from math import gcd

def SOE(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	l = []
	for p in range(2, n + 1):
		if prime[p]:
			l += [p]
	return prime

def i1():
	return int(input())

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

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

def i4():
	return input()

def i5():
	return list(str(input()))
for _ in range(i1()):
	n = i1()
	a = i3()
	if 0 not in a:
		print(n + 1, end=' ')
		for i in range(1, n + 1):
			print(i, end=' ')
		print()
	elif a[n - 1] == 0:
		for i in range(1, n + 2):
			print(i, end=' ')
		print()
	else:
		t = -1
		for i in range(0, n - 1):
			if a[i] == 0 and a[i + 1] == 1:
				t = i
				break
		if t == -1:
			print(-1)
		else:
			for i in range(1, t + 2):
				print(i, end=' ')
			print(n + 1, end=' ')
			for i in range(t + 2, n + 1):
				print(i, end=' ')
			print()


n_cases = int(input())
for current_case in range(1, n_cases + 1):
	n = int(input())
	a = list(map(int, input().split(' ')))
	first_one_ind = -1
	for (i, x) in enumerate(a):
		if x == 1:
			first_one_ind = i
			break
	if first_one_ind == -1:
		ans = list(range(n + 1))
	else:
		ans = list(range(first_one_ind)) + [n] + list(range(first_one_ind, n))
	print(' '.join([str(a + 1) for a in ans]))


def find_order(a):
	n = len(a)
	if a[-1] == 0:
		return list(range(1, n + 1)) + [n + 1]
	if a[0] == 1:
		return [n + 1] + list(range(1, n + 1))
	pos = -1
	for i in range(n - 1):
		if a[i] == 0 and a[i + 1] == 1:
			pos = i
			break
	assert pos >= 0
	return list(range(1, pos + 2)) + [n + 1] + list(range(pos + 2, n + 1))
n_t = int(input())
for t in range(n_t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	assert len(a) == n
	result = find_order(a)
	print(' '.join(map(str, result)))


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

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

def getliststr():
	return list(stdin.readline().split())

def getint():
	return int(stdin.readline().strip())

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

def pr(s):
	stdout.write(str(s) + '\n')

def prlist(l):
	stdout.write(' '.join(list(map(str, l))) + '\n')
from sys import stdin, stdout
for _ in range(getint()):
	n = getint()
	a = getlistint()
	if a[0] == 1:
		prlist([n + 1] + list(range(1, n + 1)))
		continue
	if a[-1] == 0:
		prlist(list(range(1, n + 2)))
		continue
	l = []
	for i in range(n - 1):
		if a[i] == 0 and a[i + 1] == 1:
			l = list(range(1, i + 2)) + [n + 1] + list(range(i + 2, n + 1))
			break
	if l == []:
		pr(-1)
	else:
		prlist(l)