You are given a table $a$ of size $2 \times n$ (i.e. two rows and $n$ columns) consisting of integers from $1$ to $n$.

In one move, you can choose some column $j$ ($1 \le j \le n$) and swap values $a_{1, j}$ and $a_{2, j}$ in it. Each column can be chosen no more than once.

Your task is to find the minimum number of moves required to obtain permutations of size $n$ in both first and second rows of the table or determine if it is impossible to do that.

You have to answer $t$ independent test cases.

Recall that the permutation of size $n$ is such an array of size $n$ that contains each integer from $1$ to $n$ exactly once (the order of elements doesn't matter).


-----Input-----

The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.

The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of columns in the table. The second line of the test case contains $n$ integers $a_{1, 1}, a_{1, 2}, \dots, a_{1, n}$ ($1 \le a_{1, i} \le n$), where $a_{1, i}$ is the $i$-th element of the first row of the table. The third line of the test case contains $n$ integers $a_{2, 1}, a_{2, 2}, \dots, a_{2, n}$ ($1 \le a_{2, i} \le n$), where $a_{2, i}$ is the $i$-th element of the second row of the table.

It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).


-----Output-----

For each test case print the answer: -1 if it is impossible to obtain permutation of size $n$ in both first and the second rows of the table, or one integer $k$ in the first line, where $k$ is the minimum number of moves required to obtain permutations in both rows, and $k$ distinct integers $pos_1, pos_2, \dots, pos_k$ in the second line ($1 \le pos_i \le n$) in any order — indices of columns in which you need to swap values to obtain permutations in both rows. If there are several answers, you can print any.


-----Example-----
Input
6
4
1 2 3 4
2 3 1 4
5
5 3 5 1 4
1 2 3 2 4
3
1 2 1
3 3 2
4
1 2 2 1
3 4 3 4
4
4 3 1 4
3 2 2 1
3
1 1 2
3 2 2

Output
0

2
2 3 
1
1 
2
3 4 
2
3 4 
-1

Difficulty: EASY

Starter code:

Solutions:
import sys

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

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	pos = [[] for i in range(n + 1)]
	for i in range(n):
		pos[a[i]].extend((i, 0))
		pos[b[i]].extend((i, 1))
		if len(pos[a[i]]) > 4 or len(pos[b[i]]) > 4:
			print(-1)
			return
	was = [False] * (n + 1)
	res = []
	for i in range(1, n):
		if not was[i]:
			x = i
			p = pos[i][0]
			if pos[i][1] == 1:
				(one, two) = ([p], [])
			else:
				(one, two) = ([], [p])
			first = p
			while True:
				was[x] = True
				if pos[x][0] == p:
					p = pos[x][2]
					if p == first:
						break
					r = pos[x][3]
				else:
					p = pos[x][0]
					if p == first:
						break
					r = pos[x][1]
				if r == 0:
					one.append(p)
					x = b[p]
				else:
					two.append(p)
					x = a[p]
			if len(one) > len(two):
				one = two
			res.extend(one)
	print(len(res))
	print(' '.join([str(i + 1) for i in res]))
for i in range(int(input())):
	solve()


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

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

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

def solve():
	n = int(inputi())
	aa = []
	aa.append([0] + [int(a) for a in inputi().split()])
	aa.append([0] + [int(a) for a in inputi().split()])
	ndx = [[[] for _ in range(n + 1)] for _ in range(2)]
	for i in range(n + 1):
		ndx[0][aa[0][i]].append(i)
		ndx[1][aa[1][i]].append(i)
	res = set()
	for i in range(1, n + 1):
		if len(ndx[0][i]) + len(ndx[1][i]) != 2:
			print(-1)
			return
		for r in range(2):
			if len(ndx[r][i]) == 2:
				swaps = []
				nsc = []
				for j in range(2):
					c = ndx[r][i][j]
					swaps.append([c])
					nsc.append(1)
					v = aa[1 - r][c]
					while len(ndx[1 - r][v]) == 1:
						if len(ndx[r][v]) != 1:
							print(-1)
							return
						c = ndx[r][v][0]
						swaps[-1].append(c)
						nsc[-1] += -1 if c in res else 1
						v = aa[1 - r][c]
				swaps = swaps[0] if nsc[0] <= nsc[1] else swaps[1]
				for c in swaps:
					ndx[0][aa[0][c]].remove(c)
					ndx[1][aa[1][c]].remove(c)
					(aa[0][c], aa[1][c]) = (aa[1][c], aa[0][c])
					ndx[0][aa[0][c]].append(c)
					ndx[1][aa[1][c]].append(c)
					if c in res:
						res.remove(c)
					else:
						res.add(c)
	print(len(res))
	print(' '.join(map(str, res)))

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


from sys import stdin, setrecursionlimit
from collections import deque
input = stdin.readline
setrecursionlimit(int(200000.0))

def getstr():
	return input()[:-1]

def getint():
	return int(input())

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

def getint1():
	return list(map(lambda x: int(x) - 1, input().split()))
adj = col = comp = []
cnt0 = cnt1 = 0

def dfs(us, cs, cmp, n):
	global adj, col, comp, cnt0, cnt1
	stack = [(us, cs)]
	inq = [False] * n
	inq[us] = True
	while len(stack) > 0:
		(u, c) = stack.pop()
		inq[u] = False
		col[u] = c
		if col[u] == 0:
			cnt0 += 1
		else:
			cnt1 += 1
		comp[u] = cmp
		for (v, ch) in adj[u]:
			if col[v] == -1 and (not inq[v]):
				inq[v] = True
				stack.append((v, c ^ ch))

def solve():
	global adj, col, comp, cnt0, cnt1
	n = getint()
	a = []
	pos = [[] for _ in range(n)]
	adj = [[] for _ in range(n)]
	for i in [0, 1]:
		a.append(getint1())
		for (j, x) in enumerate(a[i]):
			pos[x].append(j)
	for (i, c) in enumerate(pos):
		if len(c) != 2:
			print('-1')
			return
		if c[0] == c[1]:
			continue
		r1 = int(a[0][c[0]] != i)
		r2 = int(a[0][c[1]] != i)
		adj[c[0]].append((c[1], int(r1 == r2)))
		adj[c[1]].append((c[0], int(r1 == r2)))
	col = [-1] * n
	comp = [-1] * n
	colcnt = []
	ans = cnt = 0
	for i in range(n):
		if col[i] == -1:
			(cnt0, cnt1) = (0, 0)
			dfs(i, 0, cnt, n)
			cnt += 1
			colcnt.append((cnt0, cnt1))
			ans += min(cnt0, cnt1)
	print(ans)
	alist = []
	for i in range(n):
		chz = int(colcnt[comp[i]][0] < colcnt[comp[i]][1])
		if col[i] ^ chz:
			alist.append(i + 1)
	print(*alist)
for _ in range(getint()):
	solve()


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

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

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

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

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

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

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

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

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

@bootstrap
def dfs(r, p):
	if len(g[r]) == 1 and p != -1:
		isl[r] = 1
		yield 1
	tmp = 0
	for ch in g[r]:
		if ch != p:
			tmp += (yield dfs(ch, r))
	cnt[r] += tmp
	if p == -1 and len(g[r]) == 1:
		isl[r] = 1
		cnt[g[r][0]] += 1
	yield 0
t = N()
for i in range(t):
	n = N()
	a = RLL()
	b = RLL()
	c = Counter(a) + Counter(b)
	if any((c[i] != 2 for i in range(1, n + 1))):
		print(-1)
	else:
		fi = {}
		se = {}
		for i in range(n):
			if a[i] not in fi:
				fi[a[i]] = i
			else:
				se[a[i]] = i
			if b[i] not in fi:
				fi[b[i]] = i
			else:
				se[b[i]] = i
		uf = UFS(n + 1)
		ans = 0
		res = []
		g = [[] for i in range(1 + n)]
		for i in range(1, n + 1):
			if fi[i] != se[i]:
				uf.union(fi[i], se[i])
		for i in range(n):
			g[uf.find(i)].append(i)
		for i in range(n):
			if len(g[i]) < 2:
				continue
			rem = [g[i][0] + 1]
			inv = []
			ind = g[i][0]
			cur = b[ind]
			while cur != a[g[i][0]]:
				for j in (fi[cur], se[cur]):
					if j != ind:
						if a[j] == cur:
							rem.append(j + 1)
							cur = b[j]
						else:
							inv.append(j + 1)
							cur = a[j]
						ind = j
						break
			if len(rem) <= len(inv):
				res += rem
				ans += len(rem)
			else:
				res += inv
				ans += len(inv)
		print(ans)
		print(*res)


import sys
from collections import deque
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	data = [[] for i in range(n)]
	for i in range(n):
		data[a[i] - 1].append(i)
		data[b[i] - 1].append(i)
	for i in range(n):
		if len(data[i]) != 2:
			print(-1)
			break
	else:
		edge = [[] for i in range(n)]
		for i in range(n):
			(u, v) = (data[i][0], data[i][1])
			edge[u].append((v, i))
			edge[v].append((u, i))
		seen = [False] * n
		temp = []
		res = 0

		def dfs(v, cond):
			global temp, res
			res.append(v)
			if cond == 1:
				(up, down) = (a[v], b[v])
			else:
				(up, down) = (b[v], a[v])
			for (nv, val) in edge[v]:
				if not seen[nv]:
					seen[nv] = True
					if a[nv] == up or b[nv] == down:
						temp.append(nv)
						dfs(nv, -1)
					else:
						dfs(nv, 1)

		def bfs(i):
			global temp, res
			deq = deque([(i, 1)])
			while deq:
				(v, cond) = deq.popleft()
				res.append(v)
				if cond == 1:
					(up, down) = (a[v], b[v])
				else:
					(up, down) = (b[v], a[v])
				for (nv, val) in edge[v]:
					if not seen[nv]:
						seen[nv] = True
						if a[nv] == up or b[nv] == down:
							temp.append(nv)
							deq.append((nv, -1))
						else:
							deq.append((nv, 1))
		ans = []
		for i in range(0, n):
			if not seen[i]:
				res = []
				temp = []
				seen[i] = True
				bfs(i)
				if len(res) - len(temp) >= len(temp):
					ans += temp
				else:
					temp = set(temp)
					for v in res:
						if v not in temp:
							ans.append(v)
		if ans:
			ans = [ans[i] + 1 for i in range(len(ans))]
		print(len(ans))
		print(*ans)


for t in range(int(input())):
	n = int(input())
	aa = [[int(s) - 1 for s in input().split(' ')] for _ in [0, 1]]
	maxv = max(max(aa[0]), max(aa[1]))
	minv = min(min(aa[0]), min(aa[1]))
	if minv != 0 or maxv != n - 1:
		print(-1)
		continue
	counts = [0] * n
	index = [[] for _ in range(n)]
	for row in aa:
		for (x, a) in enumerate(row):
			counts[a] += 1
			index[a] += [x]
	if not min(counts) == 2 == max(counts):
		print(-1)
		continue
	proc = [False] * n
	ans = []
	for i in range(n):
		if proc[i]:
			continue
		swapped = set()
		used = set()
		curcol = i
		curval = aa[0][i]
		while True:
			proc[curcol] = True
			used.add(curcol)
			if aa[0][curcol] == curval:
				nexval = aa[1][curcol]
			else:
				nexval = aa[0][curcol]
				swapped.add(curcol)
			nexcol = index[nexval][1] if index[nexval][0] == curcol else index[nexval][0]
			curcol = nexcol
			curval = nexval
			if curcol == i:
				break
		part = swapped if 2 * len(swapped) <= len(used) else used.difference(swapped)
		ans += part
	print(len(ans))
	print(' '.join((str(v + 1) for v in ans)))


from collections import defaultdict, deque
import sys
input = sys.stdin.readline

def bfs(i):
	queue = deque([(i, 1)])
	while queue:
		(vertex, colour) = queue.popleft()
		res.append(vertex)
		if colour == 1:
			(up, down) = (a[vertex], b[vertex])
		else:
			(up, down) = (b[vertex], a[vertex])
		for child in graph[vertex]:
			if not vis[child]:
				vis[child] = True
				if a[child] == up or b[child] == down:
					tmp.append(child)
					queue.append((child, 0))
				else:
					queue.append((child, 1))
t = int(input())
for ii in range(t):
	n = int(input())
	a = [int(i) for i in input().split() if i != '\n']
	b = [int(i) for i in input().split() if i != '\n']
	data = [[] for _ in range(n)]
	for i in range(n):
		data[a[i] - 1].append(i)
		data[b[i] - 1].append(i)
	graph = defaultdict(list)
	for i in range(n):
		if len(data[i]) != 2:
			print(-1)
			break
	else:
		for i in range(n):
			(u, v) = (data[i][0], data[i][1])
			graph[u].append(v)
			graph[v].append(u)
		(vis, ans) = ([False] * n, [])
		for i in range(n):
			if not vis[i]:
				(tmp, res) = ([], [])
				vis[i] = True
				bfs(i)
				if len(res) - len(tmp) >= len(tmp):
					ans += tmp
				else:
					tmp = set(tmp)
					for i in res:
						if i not in tmp:
							ans.append(i)
		print(len(ans))
		ans = [i + 1 for i in ans]
		print(*ans)


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

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

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

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

def out(var):
	sys.stdout.write(str(var) + '\n')
from fractions import Fraction
INF = float('inf')
mod = int(1000000000.0) + 7
for t in range(int(data())):
	n = int(data())
	a1 = mdata()
	a2 = mdata()
	d = dd(int)
	g = [[] for i in range(n + 1)]
	for i in range(n):
		d[a1[i]] += 1
		d[a2[i]] += 1
		if a1[i] == a2[i]:
			continue
		g[a1[i]].append((a2[i], i + 1, 0))
		g[a2[i]].append((a1[i], i + 1, 1))
	if max(d.values()) > 2:
		out(-1)
		continue
	vis = [0] * (n + 1)
	vis1 = [0] * (n + 1)
	ans = []
	for i in range(1, n + 1):
		if vis[i] == 0 and g[i]:
			s = [[], []]
			vis[i] = 1
			(a, b) = (g[i][0], g[i][1])
			s[a[2]].append(a[1])
			s[1 - b[2]].append(b[1])
			vis[a[0]] = -1
			vis[b[0]] = 1
			vis1[a[1]] = 1
			vis1[b[1]] = 1
			q = []
			q.append(g[i][0][0])
			q.append(g[i][1][0])
			while q:
				a = q.pop()
				for nei in g[a]:
					if vis1[nei[1]] == 0:
						s[1 - nei[2]].append(nei[1])
						vis[nei[0]] = -1 * vis[a]
						vis1[nei[1]] = 1
						q.append(nei[0])
			if len(s[0]) < len(s[1]):
				ans += s[0]
			else:
				ans += s[1]
	out(len(ans))
	outl(ans)


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

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

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

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

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

def bootstrap(f, stack=[]):

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

def main():
	for _ in range(N()):
		n = N()
		arra = RLL()
		arrb = RLL()
		rec = [0] * (n + 1)
		prec = [[] for _ in range(n + 1)]
		for i in range(n):
			rec[arra[i]] += 1
			rec[arrb[i]] += 1
			prec[arra[i]].append(i)
			prec[arrb[i]].append(i)
		for i in range(1, n + 1):
			if rec[i] != 2:
				print(-1)
				break
		else:
			(res, reca, recb) = ([], [], [])
			vis = [0] * (n + 1)

			@bootstrap
			def dfs(node, pos):
				nonlocal reca, recb, vis
				if vis[node] == 1:
					yield None
				vis[node] = 1
				for p in prec[node]:
					if p == pos:
						continue
					if arra[p] == node:
						reca.append(p)
						yield dfs(arrb[p], p)
					else:
						recb.append(p)
						yield dfs(arra[p], p)
					yield None
				yield None
			for i in range(1, n + 1):
				if vis[i] or prec[0] == prec[1]:
					continue
				dfs(i, 0)
				if len(reca) > len(recb):
					res.extend(recb)
				else:
					res.extend(reca)
				reca.clear()
				recb.clear()
			print(len(res))
			print(*[i + 1 for i in res])
main()


import sys
inp = [int(x) for x in sys.stdin.read().split()]
ii = 0
out = []

def solve(n, A):
	same = [-1] * (2 * n)
	pos = [-1] * n
	for i in range(2 * n):
		a = A[i]
		if pos[a] == -1:
			pos[a] = i
		elif pos[a] == -2:
			return None
		else:
			p = pos[a]
			pos[a] = -2
			same[p] = i
			same[i] = p
	ans = []
	found = [0] * (2 * n)
	for root in range(2 * n):
		if found[root]:
			continue
		count0 = []
		count1 = []
		node = root
		while not found[node]:
			found[node] = 1
			found[same[node]] = 1
			if node & 1:
				count0.append(node >> 1)
			else:
				count1.append(node >> 1)
			node = same[node ^ 1]
		if len(count0) < len(count1):
			ans += count0
		else:
			ans += count1
	return ans
t = inp[ii]
ii += 1
for _ in range(t):
	n = inp[ii]
	ii += 1
	A = [x - 1 for x in inp[ii:ii + n]]
	ii += n
	B = [x - 1 for x in inp[ii:ii + n]]
	ii += n
	A = [A[i >> 1] if i & 1 == 0 else B[i >> 1] for i in range(2 * n)]
	ans = solve(n, A)
	if ans is None:
		out.append('-1')
	else:
		out.append(str(len(ans)))
		out.append(' '.join((str(x + 1) for x in ans)))
print('\n'.join(out))


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

def bfs(source, getNbr):
	q = deque([source])
	dist = {source: 0}
	while q:
		node = q.popleft()
		d = dist[node]
		for nbr in getNbr(node):
			if nbr not in dist:
				q.append(nbr)
				dist[nbr] = d + 1
	return dist

def solve(N, A1, A2):
	A = A1 + A2
	graph = [[] for i in range(2 * N)]
	for i in range(N):
		if A[i] != A[i + N]:
			graph[i].append(i + N)
			graph[i + N].append(i)
	valToCols = defaultdict(list)
	for (i, x) in enumerate(A):
		valToCols[x].append(i)
	for x in range(1, N + 1):
		if len(valToCols[x]) != 2:
			return -1
		(i, j) = valToCols[x]
		graph[i].append(j)
		graph[j].append(i)

	def getNbr(u):
		return graph[u]
	ans = []
	seen = {}
	for source in range(2 * N):
		if source not in seen:
			dist = bfs(source, getNbr)
			for u in dist.keys():
				color = dist[u] % 2
				for v in graph[u]:
					color2 = dist[v] % 2
					if color == color2:
						return -1
			cols1 = [u for u in dist.keys() if u < N and dist[u] % 2 == 0]
			cols2 = [u for u in dist.keys() if u < N and dist[u] % 2 == 1]
			if len(cols1) < len(cols2):
				ans.extend(cols1)
			else:
				ans.extend(cols2)
			seen.update(dist)
	return str(len(ans)) + '\n' + ' '.join((str(c + 1) for c in ans))
if False:
	import random
	random.seed(0)
	from itertools import combinations, product
	for t in range(10000):
		N = 5
		for perm1 in product(range(1, N + 1), repeat=N):
			for perm2 in product(range(1, N + 1), repeat=N):
				best = float('inf')
				for mask in range(1 << N):
					p1 = list(perm1)
					p2 = list(perm2)
					for i in range(N):
						if mask & 1 << i:
							(p1[i], p2[i]) = (p2[i], p1[i])
					if sorted(p1) == sorted(p2) == sorted(range(1, N + 1)):
						best = min(best, bin(mask).count('1'))
				if best == float('inf'):
					best = -1
				ans = int(str(solve(N, perm1, perm2)).split('\n')[0])
				if ans != best:
					print(perm1, perm2, best, ans)
	exit()
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	A1 = [int(x) for x in input().split()]
	A2 = [int(x) for x in input().split()]
	ans = solve(N, A1, A2)
	print(ans)


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

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

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

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

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

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

def maketo():
	atoi = [[] for _ in range(n)]
	for (i, a) in enumerate(aa):
		if a < 1 or a > n:
			return True
		atoi[a - 1].append(i)
		if len(atoi[a - 1]) > 2:
			return True
	for a in range(n):
		(u, v) = atoi[a]
		if u + n == v:
			continue
		to[u].append((v + n) % (n * 2))
		to[v].append((u + n) % (n * 2))
	return False

def dfs(u):
	flap[u % n] = (u >= n) * 1
	cur[u >= n].append(u % n + 1)
	stack = [u]
	while stack:
		u = stack.pop()
		for v in to[u]:
			if flap[v % n] == -1:
				flap[v % n] = (v >= n) * 1
				cur[v >= n].append(v % n + 1)
				stack.append(v)
			elif flap[v % n] != (v >= n) * 1:
				return True
	return False
for _ in range(II()):
	n = II()
	aa = LI() + LI()
	to = [[] for _ in range(n * 2)]
	if maketo():
		print(-1)
		continue
	ans = []
	flap = [-1] * n
	ng = False
	for u in range(n):
		if flap[u % n] != -1:
			continue
		cur = [[], []]
		ng = dfs(u)
		if len(cur[0]) < len(cur[1]):
			ans += cur[0]
		else:
			ans += cur[1]
		if ng:
			break
	if ng:
		print(-1)
	else:
		print(len(ans))
		print(*ans)


t = int(input())
Maxn = 210000
while t > 0:
	t -= 1
	n = int(input())
	a = input().split()
	b = input().split()
	a1 = [-1] * (n + 1)
	a2 = [-1] * (n + 1)
	b1 = [-1] * (n + 1)
	b2 = [-1] * (n + 1)
	for i in range(0, n):
		now = int(a[i])
		if a1[now] == -1:
			a1[now] = i
			b1[now] = 1
		else:
			a2[now] = i
			b2[now] = 1
		now = int(b[i])
		if a1[now] == -1:
			a1[now] = i
			b1[now] = 2
		else:
			a2[now] = i
			b2[now] = 2
	flag = 0
	for i in range(1, n + 1):
		if a2[i] == -1:
			print('-1')
			flag = 1
			break
	if flag:
		continue
	to = []
	nxt = []
	w = []
	que = []
	first = [-1] * (n + 1)
	col = [-1] * (n + 1)

	def add(u, v, wi):
		to.append(v)
		nxt.append(first[u])
		w.append(wi)
		first[u] = len(to) - 1
		to.append(u)
		nxt.append(first[v])
		first[v] = len(to) - 1
		w.append(wi)
	for i in range(1, n + 1):
		if a1[i] == a2[i]:
			continue
		elif b1[i] == b2[i]:
			add(a1[i], a2[i], 1)
		else:
			add(a1[i], a2[i], 0)
	ans = []
	for i in range(0, n):
		if first[i] != -1 and col[i] == -1:
			col[i] = 0
			que.append(i)
			q = [[i], []]
			while len(que):
				now = que.pop()
				cur = first[now]
				while cur != -1:
					if col[to[cur]] == -1:
						if w[cur] == 0:
							col[to[cur]] = col[now]
						else:
							col[to[cur]] = (col[now] + 1) % 2
						q[col[to[cur]]].append(to[cur])
						que.append(to[cur])
					cur = nxt[cur]
			if len(q[0]) < len(q[1]):
				while len(q[0]):
					ans.append(q[0].pop() + 1)
			else:
				while len(q[1]):
					ans.append(q[1].pop() + 1)
	print(len(ans))
	for i in ans:
		print(i, end=' ')
	print('')