Polycarp has n different binary words. A word called binary if it contains only characters '0' and '1'. For example, these words are binary: "0001", "11", "0" and "0011100".

Polycarp wants to offer his set of n binary words to play a game "words". In this game, players name words and each next word (starting from the second) must start with the last character of the previous word. The first word can be any. For example, these sequence of words can be named during the game: "0101", "1", "10", "00", "00001".

Word reversal is the operation of reversing the order of the characters. For example, the word "0111" after the reversal becomes "1110", the word "11010" after the reversal becomes "01011".

Probably, Polycarp has such a set of words that there is no way to put them in the order correspondent to the game rules. In this situation, he wants to reverse some words from his set so that:

  * the final set of n words still contains different words (i.e. all words are unique); 
  * there is a way to put all words of the final set of words in the order so that the final sequence of n words is consistent with the game rules. 



Polycarp wants to reverse minimal number of words. Please, help him.

Input

The first line of the input contains one integer t (1 ≤ t ≤ 10^4) — the number of test cases in the input. Then t test cases follow.

The first line of a test case contains one integer n (1 ≤ n ≤ 2⋅10^5) — the number of words in the Polycarp's set. Next n lines contain these words. All of n words aren't empty and contains only characters '0' and '1'. The sum of word lengths doesn't exceed 4⋅10^6. All words are different.

Guaranteed, that the sum of n for all test cases in the input doesn't exceed 2⋅10^5. Also, guaranteed that the sum of word lengths for all test cases in the input doesn't exceed 4⋅10^6.

Output

Print answer for all of t test cases in the order they appear.

If there is no answer for the test case, print -1. Otherwise, the first line of the output should contain k (0 ≤ k ≤ n) — the minimal number of words in the set which should be reversed. The second line of the output should contain k distinct integers — the indexes of the words in the set which should be reversed. Words are numerated from 1 to n in the order they appear. If k=0 you can skip this line (or you can print an empty line). If there are many answers you can print any of them.

Example

Input


4
4
0001
1000
0011
0111
3
010
101
0
2
00000
00001
4
01
001
0001
00001


Output


1
3 
-1
0

2
1 2

Source: codeforces | Difficulty: HARD
Tags: Mathematics

String algorithms

Data structures

Implementation


Solutions:
t = int(input())
for _ in range(t):
	n = int(input())
	words = []
	for i in range(n):
		words.append(input())
	same_1 = []
	same_0 = []
	zero_1 = []
	one_0 = []
	index_zero_1 = []
	index_one_0 = []
	for (index, w) in enumerate(words):
		if w[0] == w[-1]:
			if w[0] == '0':
				same_0.append(w)
			elif w[0] == '1':
				same_1.append(w)
		elif w[0] == '0' and w[-1] == '1':
			zero_1.append(w)
			index_zero_1.append(index)
		elif w[0] == '1' and w[-1] == '0':
			one_0.append(w)
			index_one_0.append(index)
	if len(same_1) > 0 and len(same_0) == 0 and (len(zero_1) == 0) and (len(one_0) == 0):
		print(0)
		continue
	elif len(same_0) > 0 and len(same_1) == 0 and (len(zero_1) == 0) and (len(one_0) == 0):
		print(0)
		continue
	elif len(same_0) > 0 and len(same_1) > 0 and (len(zero_1) == 0) and (len(one_0) == 0):
		print(-1)
		continue
	elif len(one_0) == len(zero_1) or len(one_0) == len(zero_1) - 1 or len(one_0) == len(zero_1) + 1 or (len(one_0) - 1 == zero_1) or (len(one_0) + 1 == zero_1):
		print(0)
	else:
		if len(zero_1) >= len(one_0):
			words_to_reverse = zero_1
			words_set = set(one_0)
			index_map = index_zero_1
			required = (len(zero_1) - len(one_0)) // 2
		elif len(one_0) > len(zero_1):
			words_to_reverse = one_0
			words_set = set(zero_1)
			index_map = index_one_0
			required = (len(one_0) - len(zero_1)) // 2
		indices = []
		for (index, w) in enumerate(words_to_reverse):
			if w[::-1] in words_set:
				continue
			else:
				indices.append(index_map[index] + 1)
				if len(indices) >= required:
					break
				else:
					continue
		print(len(indices))
		print(*indices, sep=' ')


import sys
from collections import defaultdict
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	N = int(input())
	w00 = 0
	w11 = 0
	w01 = defaultdict(int)
	w10 = defaultdict(int)
	for i in range(1, N + 1):
		w = input().rstrip('\n')
		if w[0] == w[-1] == '0':
			w00 = 1
		elif w[0] == w[-1] == '1':
			w11 = 1
		elif w[0] == '0':
			w_rev = w[::-1]
			w10[w_rev] = -1
			if w01[w] == 0:
				w01[w] = i
		else:
			w_rev = w[::-1]
			w01[w_rev] = -1
			if w10[w] == 0:
				w10[w] = i
	if w00 == w11 == 1:
		if len(w01) == len(w10) == 0:
			print(-1)
			continue
	ans = 0
	i01 = []
	i10 = []
	for i in w01.values():
		if i > 0:
			i01.append(i)
	for i in w10.values():
		if i > 0:
			i10.append(i)
	if len(i01) > len(i10):
		ans = i01[:(len(i01) - len(i10)) // 2]
	else:
		ans = i10[:(len(i10) - len(i01)) // 2]
	print(len(ans))
	print(*ans)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
t = int(input())
for y in range(t):
	n = int(input())
	a = 0
	b = 0
	c = []
	d = []
	cc = 0
	ccc = 0
	dd = dict()
	l = []
	for i in range(n):
		s = input()
		l.append(s)
		dd[s] = 1
	for i in range(n):
		if l[i][0] == '0' and l[i][-1] == '1':
			b += 1
			t = l[i][::-1]
			if t not in dd:
				c.append(i + 1)
		if l[i][0] == '1' and l[i][-1] == '0':
			a += 1
			t = l[i][::-1]
			if t not in dd:
				d.append(i + 1)
		if l[i][0] == '1' and l[i][-1] == '1':
			cc += 1
		if l[i][0] == '0' and l[i][-1] == '0':
			ccc += 1
	if cc > 0:
		b += 1
	if ccc > 0:
		a += 1
	if cc == n or ccc == n:
		print(0)
		continue
	if cc + ccc == n:
		print(-1)
		continue
	if len(d) > len(c):
		ind = (len(d) - len(c)) // 2
		if len(d) < ind:
			print(-1)
			continue
		else:
			print(ind)
			for i in range(ind):
				print(d[i], end=' ')
			print()
	else:
		ind = (len(c) - len(d)) // 2
		if len(c) < ind:
			print(-1)
			continue
		else:
			print(ind)
			for i in range(ind):
				print(c[i], end=' ')
			print()


from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
DBG = True
BIG = 999999999
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)
t = inn()
for _ in range(t):
	n = inn()
	a00 = []
	a01 = []
	a10 = []
	a11 = []
	for i in range(n):
		s = input().strip()
		if s[0] == '0' and s[-1] == '0':
			a00.append((s, i))
		elif s[0] == '0' and s[-1] == '1':
			a01.append((s, i))
		elif s[0] == '1' and s[-1] == '0':
			a10.append((s, i))
		else:
			a11.append((s, i))
	if len(a00) > 0 and len(a11) > 0 and (len(a01) == 0) and (len(a10) == 0):
		print(-1)
		continue
	dif = len(a01) - len(a10)
	k = abs(dif)
	if k <= 1:
		print(0)
		continue
	h = {}
	if dif > 0:
		u = a01
		for x in a10:
			h[x[0][::-1]] = 1
	else:
		u = a10
		for x in a01:
			h[x[0][::-1]] = 1
	rev = []
	for x in u:
		if x[0] in h:
			continue
		rev.append(x[1] + 1)
		k -= 2
		if k <= 1:
			break
	print(len(rev))
	for (i, x) in enumerate(rev):
		printn((' ' if i > 0 else '') + str(x))
	print('')


import math
t = int(input())
for _ in range(t):
	n = int(input())
	w00 = []
	w01 = []
	w10 = []
	w11 = []
	dic = {}
	l00 = 0
	l01 = 0
	l10 = 0
	l11 = 0
	arr = []
	for i in range(n):
		s = input()
		dic[s] = s
		arr.append(s)
	for i in range(n):
		s = arr[i]
		if s[0] == '0' and s[-1] == '0':
			if s[::-1] not in dic:
				w00.append(i + 1)
			l00 += 1
		elif s[0] == '0' and s[-1] == '1':
			if s[::-1] not in dic:
				w01.append(i + 1)
			l01 += 1
		elif s[0] == '1' and s[-1] == '0':
			if s[::-1] not in dic:
				w10.append(i + 1)
			l10 += 1
		elif s[0] == '1' and s[-1] == '1':
			if s[::-1] not in dic:
				w11.append(i + 1)
			l11 += 1
	d = abs(l01 - l10)
	if l00 == 0 and l11 == 0:
		if d <= 1:
			print(0)
			print()
		elif l10 > l01:
			if len(w10) >= d // 2:
				print(d // 2)
				print(*w10[:d // 2])
			else:
				print(-1)
		elif len(w01) >= d // 2:
			print(d // 2)
			print(*w01[:d // 2])
		else:
			print(-1)
	elif l00 == 0 and l11 > 0:
		if d <= 1:
			print(0)
			print()
		else:
			print(d // 2)
			if l10 > l01:
				print(*w10[:d // 2])
			else:
				print(*w01[:d // 2])
	elif l00 > 0 and l11 == 0:
		if d <= 1:
			print(0)
			print()
		else:
			print(d // 2)
			if l10 > l01:
				print(*w10[:d // 2])
			else:
				print(*w01[:d // 2])
	elif l00 > 0 and l11 > 0:
		if l01 == 0 and l10 == 0:
			print(-1)
		elif d <= 1:
			print(0)
			print()
		else:
			print(d // 2)
			if l10 > l01:
				print(*w10[:d // 2])
			else:
				print(*w01[:d // 2])


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def solve():
	oo = 0
	ii = 0
	oi = 0
	oii = set()
	ioo = set()
	io = 0
	oi_ = io_ = 0
	d = dict()
	n = int(input())
	for i in range(n):
		w = input()
		d[w] = i
		l = int(w[0])
		r = int(w[-1])
		if l == r == 0:
			oo += 1
		elif l == r == 1:
			ii += 1
		elif l == 0 and r == 1:
			rw = w[::-1]
			if rw in d:
				io -= 1
				ioo.remove(d[rw])
				io_ += 1
				oi_ += 1
			else:
				oi += 1
				oii.add(i)
		else:
			rw = w[::-1]
			if rw in d:
				oi -= 1
				oii.remove(d[rw])
				oi_ += 1
				io_ += 1
			else:
				io += 1
				ioo.add(i)
	ans = -1
	l = []
	su = oi + oi_ + io + io_
	if su == 0:
		if oo * ii != 0:
			ans = -1
		else:
			ans = 0
	else:
		k = su // 2 + su % 2
		if oi + oi_ < io + io_:
			(oi, oi_) = (io, io_)
			(oii, ioo) = (ioo, oii)
		if oi_ > k:
			ans = -1
		else:
			ans = oi + oi_ - k
			for (i, j) in enumerate(oii):
				if i == ans:
					break
				l.append(j + 1)
	print(ans)
	if ans != -1:
		print(*l)
t = int(input())
for i in range(t):
	solve()


def main():
	import sys, math
	from heapq import heapify, heappush, heappop
	from collections import defaultdict as dd, deque

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

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

	def out(*var, end='\n'):
		sys.stdout.write(' '.join(map(str, var)) + end)
	INF = int(1000000000.0)
	mod = int(1000000000.0) + 7
	for t in range(int(data())):
		n = int(data())
		s10 = dd(int)
		s01 = dd(int)
		m00 = m11 = m01 = m10 = 0
		cnt = 0
		for i in range(n):
			a = data()
			if a[0] == '1':
				if a[-1] == '1':
					m11 += 1
				else:
					m10 += 1
					if s01[a[::-1]] == 0:
						s10[a] = i + 1
						cnt += 1
					else:
						s01[a[::-1]] = 0
						cnt -= 1
			elif a[-1] == '1':
				m01 += 1
				if s10[a[::-1]] == 0:
					cnt += 1
					s01[a] = i + 1
				else:
					s10[a[::-1]] = 0
					cnt -= 1
			else:
				m00 += 1
		if m00 > 0 and m11 > 0 and (m10 + m01 == 0):
			out(-1)
		elif abs(m10 - m01) // 2 > cnt:
			out(-1)
		else:
			cnt = abs(m10 - m01) // 2
			ans = []
			out(cnt)
			if m10 > m01:
				for i in s10:
					if cnt == 0:
						break
					if s10[i] != 0:
						ans.append(s10[i])
						cnt -= 1
			else:
				for i in s01:
					if cnt == 0:
						break
					if s01[i] != 0:
						ans.append(s01[i])
						cnt -= 1
			out(*ans)
main()


for _ in range(int(input())):
	n = int(input())
	s = [str()] * n
	st = set()
	cnt_11 = 0
	cnt_00 = 0
	patt_01 = []
	patt_10 = []
	for i in range(n):
		s[i] = input()
		if s[i][0] == s[i][-1]:
			if s[i][0] == '0':
				cnt_00 += 1
			else:
				cnt_11 += 1
		else:
			if s[i][0] == '0':
				patt_01.append(i)
			else:
				patt_10.append(i)
			st.add(s[i])
	has_duo = [False] * n
	for i in range(n):
		if s[i][::-1] in st:
			has_duo[i] = True
	if (cnt_11 != 0 and cnt_00 != 0) and (len(patt_01) == 0 and len(patt_10) == 0):
		print(-1)
		continue
	else:
		cnt_01 = len(patt_01)
		cnt_10 = len(patt_10)
		if cnt_01 < cnt_10:
			(cnt_01, cnt_10) = (cnt_10, cnt_01)
			(patt_01, patt_10) = (patt_10, patt_01)
		delta = (cnt_01 - cnt_10) // 2
		rev = []
		for patt in patt_01:
			if delta == 0:
				break
			if not has_duo[patt]:
				rev.append(patt + 1)
				delta -= 1
		if delta == 0:
			print(len(rev))
			print(*rev)
		else:
			print(-1)


import sys
import collections
from collections import Counter
import itertools
import math
import timeit

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

def divs(n, start=1):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def flin(d, x, default=-1):
	left = right = -1
	for i in range(len(d)):
		if d[i] == x:
			if left == -1:
				left = i
			right = i
	if left == -1:
		return (default, default)
	else:
		return (left, right)

def ceil(n, k):
	return n // k + (n % k != 0)

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

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

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

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

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)
t = ii()
for _ in range(t):
	oz = zo = oo = zz = 0
	n = ii()
	d = ddl()
	pool = set()
	st = []
	pos01 = []
	pos10 = []
	for i in range(n):
		s = input()
		pool.add(s)
		st.append(s)
		if s[0] != s[-1]:
			if s[0] == '1':
				oz += 1
				pos10.append(i)
			else:
				zo += 1
				pos01.append(i)
		elif s[0] == '1':
			oo += 1
		else:
			zz += 1
	if min(zz, oo) > 0 and max(zo, oz) == 0:
		print(-1)
		continue
	q = abs(zo - oz)
	if q <= 1:
		print('0\n')
		continue
	if zo > oz:
		r = 0
		res = []
		for i in pos01:
			if st[i][::-1] not in pool:
				r += 1
				zo -= 1
				oz += 1
				res.append(i + 1)
			if abs(zo - oz) <= 1:
				break
	else:
		r = 0
		res = []
		for i in pos10:
			if st[i][::-1] not in pool:
				r += 1
				oz -= 1
				zo += 1
				res.append(i + 1)
			if abs(zo - oz) <= 1:
				break
	if abs(zo - oz) <= 1:
		print(r)
		prr(res, ' ')
	else:
		print(-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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush

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)

def ctd(chr):
	return ord(chr) - ord('a')
mod = 998244353
INF = float('inf')

def main():
	for _ in range(N()):
		n = N()
		dic = {'11': 0, '00': 0, '10': 0, '01': 0}
		ind1 = []
		ind2 = []
		arr = []
		for i in range(n):
			s = input()
			arr.append(s)
			if s[0] == '1' and s[-1] == '1':
				dic['11'] += 1
			if s[0] == '0' and s[-1] == '0':
				dic['00'] += 1
			if s[0] == '1' and s[-1] == '0':
				dic['10'] += 1
				ind1.append(i + 1)
			if s[0] == '0' and s[-1] == '1':
				dic['01'] += 1
				ind2.append(i + 1)
		s = set(arr)
		if dic['10'] == 0 and dic['01'] == 0:
			print(0 if dic['11'] == 0 or dic['00'] == 0 else -1)
		else:
			dif = abs(len(ind1) - len(ind2))
			ret = []
			tag = True
			num = dif // 2
			if len(ind1) < len(ind2):
				(ind1, ind2) = (ind2, ind1)
			for i in ind1:
				if arr[i - 1][::-1] not in s:
					ret.append(i)
			print(num)
			print(*ret[:num])
main()


import sys
import math
from collections import defaultdict, Counter, deque
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')
t = int(input())
for i in range(t):
	n = int(input())
	l = set()
	l1 = defaultdict(set)
	d = {}
	for j in range(n):
		s = input()
		if s[0] != s[-1]:
			l1[s[0], s[-1]].add(s)
		else:
			l.add(s[0])
		d[s] = j + 1
	if len(l1) == 0:
		if len(l) == 2:
			print(-1)
		else:
			print(0)
		continue
	l = []
	p = 0
	if len(l1['0', '1']) >= len(l1['1', '0']):
		ans = max(0, len(l1['0', '1']) - len(l1['1', '0']) - 1)
		ans = (ans + 1) // 2
		if ans == 0:
			print(0)
			continue
		for j in l1['0', '1']:
			s1 = j[::-1]
			if s1 not in l1['1', '0']:
				p += 1
				l.append(d[j])
				if p == ans:
					print(ans)
					print(*l)
					break
		else:
			print(-1)
	else:
		ans = max(0, abs(len(l1['0', '1']) - len(l1['1', '0'])) - 1)
		ans = (ans + 1) // 2
		if ans == 0:
			print(0)
			continue
		for j in l1['1', '0']:
			s1 = j[::-1]
			if s1 not in l1['0', '1']:
				p += 1
				l.append(d[j])
				if p == ans:
					print(ans)
					print(*l)
					break
		else:
			print(-1)


import sys, math
MOD = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	(oo, zo, oz, zz) = ([], [], [], [])
	actual = []
	act_set = set()
	for i in range(n):
		s = input()
		actual.append(s)
		act_set.add(s)
		if s[0] == '0':
			if s[-1] == '0':
				zz.append(i + 1)
			else:
				zo.append(i + 1)
		elif s[-1] == '0':
			oz.append(i + 1)
		else:
			oo.append(i + 1)
	if len(oz) == 0 and len(zo) == 0 and (len(oo) != 0) and (len(zz) != 0):
		print(-1)
		continue
	oz.sort(key=lambda x: 1 if actual[x - 1][::-1] in act_set else 0)
	zo.sort(key=lambda x: 1 if actual[x - 1][::-1] in act_set else 0)
	while len(oz) > 0 and len(zo) > 0:
		(oz.pop(), zo.pop())
	if len(oz) == 0:
		ans = zo[:len(zo) // 2]
	else:
		ans = oz[:len(oz) // 2]
	ok = True
	for indx in ans:
		if actual[indx - 1][::-1] in act_set:
			ok = False
			break
	print(len(ans))
	print(*ans)


from __future__ import division, print_function
import itertools
import sys
import os
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def is_it_local():
	script_dir = str(os.getcwd()).split('/')
	username = 'dipta007'
	return username in script_dir

def READ(fileName):
	if is_it_local():
		sys.stdin = open(f'./{fileName}', 'r')
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 not is_it_local():
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')

def input1(type=int):
	return type(input())

def input2(type=int):
	[a, b] = list(map(type, input().split()))
	return (a, b)

def input3(type=int):
	[a, b, c] = list(map(type, input().split()))
	return (a, b, c)

def input_array(type=int):
	return list(map(type, input().split()))

def input_string():
	s = input()
	return list(s)

def is_it_okay(st01, st10):
	return abs(st01 - st10) <= 1

def is_it_double(st, mp):
	if mp.get(st[::-1], 0) == 1:
		return True
	return False

def main():
	t = input1()
	for ci in range(t):
		n = input1()
		mat = []
		(st01, st10) = (0, 0)
		mp = {}
		for i in range(n):
			st = input()
			now = [st]
			mp[st] = 1
			if st[0] == '0' and st[-1] == '1':
				st01 += 1
				now.append(0)
				now.append(1)
			elif st[0] == '1' and st[-1] == '0':
				st10 += 1
				now.append(1)
				now.append(0)
			else:
				now.append(ord(st[0]) - 48)
				now.append(ord(st[-1]) - 48)
			mat.append(now)
		swapped = []
		if st01 == 0 and st10 == 0:
			flg = 0
			nw = mat[0]
			for [st, a, b] in mat:
				if nw[1] != a or nw[2] != b:
					print(-1)
					flg = 1
					break
			if not flg:
				print(0)
				print('')
		elif is_it_okay(st01, st10):
			print(0)
			print('')
		else:
			for (i, [s, a, b]) in enumerate(mat):
				if st01 > st10 + 1 and a == 0 and (b == 1) and (not is_it_double(s, mp)):
					swapped.append(i)
					mp[s] -= 1
					mp[s[::-1]] = 1
					st01 -= 1
					st10 += 1
				elif st10 > st01 + 1 and a == 1 and (b == 0) and (not is_it_double(s, mp)):
					swapped.append(i)
					mp[s] -= 1
					mp[s[::-1]] = 1
					st10 -= 1
					st01 += 1
			if is_it_okay(st01, st10):
				print(len(swapped))
				print(' '.join([str(x + 1) for x in swapped]))
			else:
				print(-1)
	pass
main()


import sys
for _ in range(int(input())):
	n = int(input())
	count = [0, 0, 0, 0]
	words = [sys.stdin.readline().rstrip() for _ in range(n)]
	s = set(words)
	index01 = []
	index10 = []
	for i in range(n, 0, -1):
		w = words.pop()
		if w[0] == '0' and w[-1] == '1':
			count[0] += 1
			if w[::-1] not in s:
				index01.append(i)
		elif w[0] == '1' and w[-1] == '0':
			count[1] += 1
			if w[::-1] not in s:
				index10.append(i)
		elif w[0] == '0' and w[-1] == '0':
			count[2] += 1
		else:
			count[3] += 1
	if sum(count[:2]) == 0:
		if count[2] > 0 and count[3] > 0:
			print(-1)
		else:
			print(0)
		continue
	if abs(count[0] - count[1]) <= 1:
		print(0)
		continue
	x = (count[0] + count[1] + 1) // 2
	if count[0] > count[1]:
		dx = count[0] - x
		if dx <= len(index01):
			print(dx)
			print(*index01[:dx])
		else:
			print(-1)
	else:
		dx = count[1] - x
		if dx <= len(index10):
			print(dx)
			print(*index10[:dx])
		else:
			print(-1)


t = int(input())

def hs(s):
	p = 41
	mod = 10 ** 9 + 7
	ans = 0
	for i in range(len(s)):
		ans = (ans * p + ord(s[i])) % mod
	return ans
while t:
	n = int(input())
	st = set()
	a = [0] * 4
	b = []
	c = []
	has = [0] * n
	par = [0] * n
	for i in range(n):
		s = input()
		x = 0
		if s[0] == '1':
			x += 2
		if s[len(s) - 1] == '1':
			x += 1
		a[x] += 1
		h1 = hs(s)
		s = s[::-1]
		h = hs(s)
		st.add(h1)
		has[i] = h
		par[i] = x
	for i in range(n):
		if has[i] not in st:
			if par[i] == 1:
				b.append(i)
			if par[i] == 2:
				c.append(i)
	if a[0] != 0 and a[3] != 0 and (a[1] == 0) and (a[2] == 0):
		print(-1)
	else:
		z = a[1] - a[2]
		if z >= 0:
			if len(b) >= z // 2:
				print(z // 2)
				for i in range(z // 2):
					print(b[i] + 1, end=' ')
				print()
			else:
				print(-1)
		else:
			z = abs(z)
			if len(c) >= z // 2:
				print(z // 2)
				for i in range(z // 2):
					print(c[i] + 1, end=' ')
				print()
			else:
				print(-1)
	t -= 1


import sys
from collections import Counter

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	A = [''] * N
	org = [''] * N
	se = set()
	for i in range(N):
		S = input()
		se.add(S)
		org[i] = S
		A[i] = S[0] + S[-1]
	C = Counter(A)
	if len(C) == 1 and C['00'] > 0 or (len(C) == 1 and C['11'] > 0):
		print(0)
		print()
	elif len(C) == 2 and C['00'] > 0 and (C['11'] > 0):
		print(-1)
	else:
		cnt = 0
		ans = []
		if C['01'] > C['10']:
			diff = C['01'] - C['10']
			while diff >= 2:
				cnt += 1
				diff -= 2
			for (i, a) in enumerate(A):
				if len(ans) == cnt:
					break
				if a == '01' and org[i][::-1] not in se:
					ans.append(i + 1)
		if C['10'] > C['01']:
			diff = C['10'] - C['01']
			while diff >= 2:
				cnt += 1
				diff -= 2
			for (i, a) in enumerate(A):
				if len(ans) == cnt:
					break
				if a == '10' and org[i][::-1] not in se:
					ans.append(i + 1)
		print(len(ans))
		print(*ans)


import sys as __sys
ZERO = '0'
ONE = '1'

def what_should_reverse(strings):
	enumerated_strings = list(enumerate(strings))
	counter = {(ZERO, ZERO): 0, (ZERO, ONE): 0, (ONE, ZERO): 0, (ONE, ONE): 0}
	for (i, s) in enumerated_strings:
		counter[s[0], s[-1]] += 1
	if counter[ZERO, ONE] == 0 and counter[ONE, ZERO] == 0:
		if counter[ZERO, ZERO] != 0 and counter[ONE, ONE] != 0:
			raise ValueError
		else:
			return []
	count_01 = counter[ZERO, ONE]
	count_10 = counter[ONE, ZERO]
	if __are_fine_counts(count_01, count_10):
		return []
	if count_01 > count_10:
		type_to_reverse = (ZERO, ONE)
		reversions_n = 0
		while not __are_fine_counts(count_01, count_10):
			reversions_n += 1
			count_01 -= 1
			count_10 += 1
	else:
		type_to_reverse = (ONE, ZERO)
		reversions_n = 0
		while not __are_fine_counts(count_01, count_10):
			reversions_n += 1
			count_10 -= 1
			count_01 += 1
	enumerated_01 = []
	enumerated_rev_10 = []
	for iv in enumerated_strings:
		if iv[1][0] == iv[1][-1]:
			continue
		if iv[1][0] == ZERO:
			enumerated_01.append(iv)
		else:
			enumerated_rev_10.append((iv[0], iv[1][::-1]))
	del enumerated_strings, counter, count_01, count_10
	if type_to_reverse == (ONE, ZERO):
		(enumerated_01, enumerated_rev_10) = (enumerated_rev_10, enumerated_01)
		type_to_reverse = (ZERO, ONE)
	enumerated_01.sort(key=lambda iv: iv[1])
	enumerated_rev_10.sort(key=lambda iv: iv[1])
	result_indices = []
	i_01 = 0
	i_10 = 0
	while len(result_indices) != reversions_n:
		while i_10 < len(enumerated_rev_10) and enumerated_rev_10[i_10][1] < enumerated_01[i_01][1]:
			i_10 += 1
		if i_10 == len(enumerated_rev_10) or enumerated_01[i_01][1] != enumerated_rev_10[i_10][1]:
			result_indices.append(enumerated_01[i_01][0])
		i_01 += 1
	return result_indices

def __are_fine_counts(count_01, count_10):
	return count_01 == count_10 or count_01 + 1 == count_10 or count_01 - 1 == count_10

def __main():
	t = int(input())
	for i_t in range(t):
		(n,) = __read_ints()
		strings = [__read_line() for i_s in range(n)]
		try:
			result = what_should_reverse(strings)
		except ValueError:
			print(-1)
		else:
			print(len(result))
			print(*[i + 1 for i in result])

def __read_line():
	result = __sys.stdin.readline()
	assert result[-1] == '\n'
	return result[:-1]

def __read_ints():
	return map(int, __read_line().split())
__main()


from sys import stdin, stdout
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	words = {'01': set(), '10': set(), '00': set(), '11': set()}
	indices = {}
	for i in range(1, n + 1):
		w = stdin.readline().strip()
		words[w[0] + w[-1]].add(w)
		indices[w] = i
	if words['00'] and words['11']:
		if not words['01'] and (not words['10']):
			stdout.write('-1\n')
			continue
	ans = []
	(wa, wb) = (words['01'], words['10'])
	if len(wb) > len(wa):
		(wa, wb) = (wb, wa)
	diff = len(wa) - len(wb)
	if diff > 1:
		revwb = set((w[::-1] for w in wb))
		avail = wa - revwb
		if len(avail) < diff - 1:
			stdout.write('-1\n')
			continue
		else:
			while diff > 1:
				w = avail.pop()
				ans.append(str(indices[w]))
				diff -= 2
	stdout.write('{}\n'.format(len(ans)))
	stdout.write(' '.join(ans) + '\n')


import sys
from collections import defaultdict
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	dif = defaultdict(list)
	same = defaultdict(list)
	vis = defaultdict(int)
	words = []
	for i in range(n):
		s = sys.stdin.readline()[:-1]
		vis[s] = 1
		words.append(s)
		if s[0] == s[-1] == '0':
			same['0'].append(i)
		if s[0] == s[-1] == '1':
			same['1'].append(i)
		if s[0] == '1' and s[-1] == '0':
			dif['1'].append(i)
		if s[0] == '0' and s[-1] == '1':
			dif['0'].append(i)
	count = 0
	ans = []
	(a, b) = (len(dif['0']), len(dif['1']))
	if a == b:
		if a == b == 0 and len(same['0']) != 0 and (len(same['1']) != 0):
			print(-1)
			continue
		pass
	elif a > b:
		x = a + b
		tar = x // 2
		if a - b > 1:
			count = tar - b
			c = 0
			for i in dif['0']:
				if c == count:
					break
				if vis[words[i][::-1]] == 0:
					ans.append(i + 1)
					c += 1
			if c != count:
				print(-1)
				continue
	else:
		x = (a + b) // 2
		tar = x
		if b - a > 1:
			count = tar - a
			c = 0
			for i in dif['1']:
				if c == count:
					break
				if vis[words[i][::-1]] == 0:
					ans.append(i + 1)
					c += 1
			if c != count:
				print(-1)
				continue
	print(count)
	print(*ans)


from collections import defaultdict
t = int(input())
for tc in range(t):
	n = int(input())
	arr = ['dummy'] * (n + 1)
	rev = [True] * (n + 1)
	idx_dic = dict()
	cnt_dic = defaultdict(lambda : 0)
	for i in range(1, n + 1):
		st = input()
		arr[i] = st[0] + st[-1]
		cnt_dic[arr[i]] = cnt_dic[arr[i]] + 1
		idx_dic[st] = i
		rev_st = st[::-1]
		if rev_st in idx_dic:
			rev[i] = False
			rev[idx_dic[rev_st]] = False
	rev_10 = []
	rev_01 = []
	for i in range(1, n + 1):
		if arr[i] == '10' and rev[i] == True:
			rev_10.append(i)
		if arr[i] == '01' and rev[i] == True:
			rev_01.append(i)
	if cnt_dic['10'] == 0 and cnt_dic['01'] == 0:
		if cnt_dic['00'] == 0 or cnt_dic['11'] == 0:
			print(0)
			print('')
		else:
			print(-1)
	else:
		diff = cnt_dic['10'] - cnt_dic['01']
		if abs(diff) <= 1:
			print(0)
			print('')
		elif diff > 0:
			ans = diff // 2
			if ans <= len(rev_10):
				print(ans)
				print(*rev_10[:ans])
			else:
				print(-1)
		elif diff < 0:
			ans = -diff // 2
			if ans <= len(rev_01):
				print(ans)
				print(*rev_01[:ans])
			else:
				print(-1)


a = int(input())
from collections import *
for i in range(a):
	s = int(input())
	al = defaultdict(int)
	ans = []
	dns = []
	flag = 0
	for i in range(s):
		q = input()
		al[q] += 1
		ans.append(q)
	g1 = []
	g2 = []
	g3 = 0
	g4 = 0
	for i in range(len(ans)):
		rot = 1
		t = ans[i][::-1]
		if al[t] == 1:
			rot = 0
		if t[0] == t[-1]:
			if t[0] == '1':
				g3 += 1
			else:
				g4 += 1
		if t[0] != t[-1]:
			if ans[i][0] == '0':
				g1.append([rot, ans[i], i])
			else:
				g2.append([rot, ans[i], i])
	g1.sort()
	g2.sort()
	if min(g4, g3) > 0 and max(len(g1), len(g2)) == 0:
		print(-1)
		continue
	ans = []
	if len(g2) > len(g1):
		t1 = g1.copy()
		g1 = g2.copy()
		g2 = t1.copy()
	if len(g1) <= len(g2) + 1:
		print(0)
		print(' ')
		continue
	final = []
	x1 = []
	x2 = []
	t1 = len(g2)
	for i in range(t1, len(g1)):
		if g1[i][0] == 1:
			x1.append(g1[i])
		else:
			x2.append(g2[i])
	if len(x2) > len(x1) + 1:
		print(-1)
		continue
	rot = 0
	i = 0
	j = 0
	while i < len(x1) or j < len(x2):
		if rot == 0 and j < len(x2):
			j += 1
			rot = 1
			continue
		if rot == 0 and j == len(x2):
			rot = 1
			i += 1
			continue
		if rot == 1:
			final.append(x1[i][2] + 1)
			i += 1
			rot = 0
			continue
	print(len(final))
	print(*final)


import sys
from sys import stdin, stdout
import bisect
import math
import heapq

def modinv(n, p):
	return pow(n, p - 2, p)

def cin():
	return map(int, sin().split())

def ain():
	return list(map(int, sin().split()))

def sin():
	return input()

def inin():
	return int(input())
import math

def Divisors(n):
	l = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
	return l

def main():
	t = inin()
	for _ in range(t):
		a = b = c = d = 0
		e = set()
		f = set()
		x = y = 0
		dd = {}
		n = inin()
		for i in range(n):
			s = sin()
			dd[s] = i
			l = int(s[0])
			r = int(s[-1])
			if l == r == 0:
				a += 1
			elif l == r == 1:
				b += 1
			elif l == 0 and r == 1:
				rw = s[::-1]
				if rw in dd:
					d -= 1
					f.remove(dd[rw])
					y += 1
					x += 1
				else:
					c += 1
					e.add(i)
			else:
				rw = s[::-1]
				if rw in dd:
					c -= 1
					e.remove(dd[rw])
					x += 1
					y += 1
				else:
					d += 1
					f.add(i)
		ans = -1
		l = []
		su = c + x + d + y
		if su == 0:
			if a * b != 0:
				ans = -1
			else:
				ans = 0
		else:
			k = su // 2 + su % 2
			if c + x < d + y:
				(c, x) = (d, y)
				(e, f) = (f, e)
			if x > k:
				ans = -1
			else:
				ans = c + x - k
				for (i, j) in enumerate(e):
					if i == ans:
						break
					l.append(j + 1)
		print(ans)
		if ans != -1:
			print(*l)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

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

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

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

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

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

class IOWrapper(IOBase):

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

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


t = int(input())
for _ in range(t):
	cnt = 0
	ans = 0
	ssum = 0
	n = int(input())
	mp = {}
	s = []
	for i in range(n):
		nn = str(input())
		s.append(nn)
		mp[nn] = i + 1
		if s[i][0] == '0' and s[i][len(s[i]) - 1] == '0':
			cnt += 1
		elif s[i][0] == '1' and s[i][len(s[i]) - 1] == '1':
			ans += 1
		else:
			ssum += 1
	if (cnt > 0 and ans > 0) and ssum == 0:
		print(-1)
	else:
		can_r = []
		cannot_r = []
		for i in range(n):
			ss = s[i]
			ss = ss[::-1]
			if ss[0] == ss[len(ss) - 1]:
				continue
			if ss not in mp:
				can_r.append(s[i])
		ol = 0
		lo = 0
		for x in can_r:
			if x[0] == '0':
				ol += 1
			else:
				lo += 1
		cnt = min(ol, lo)
		ol -= cnt
		lo -= cnt
		print(max(lo, ol) // 2)
		for x in can_r:
			if ol > 1 and x[0] == '0' and (x[len(x) - 1] == '1'):
				print(mp[x], end=' ')
				ol -= 2
			elif lo > 1 and x[0] == '1' and (x[len(x) - 1] == '0'):
				print(mp[x], end=' ')
				lo -= 2


t = int(input())
for _ in range(t):
	n = int(input())
	it = []
	oo = 0
	zz = 0
	oz = 0
	zo = 0
	tt = []
	for i in range(n):
		it.append(input())
		if it[-1][0] == '0' and it[-1][-1] == '0':
			zz += 1
		elif it[-1][0] == '1' and it[-1][-1] == '1':
			oo += 1
		elif it[-1][0] == '0' and it[-1][-1] == '1':
			zo += 1
			tt.append((it[-1], i))
		else:
			oz += 1
			tt.append((it[-1], i))
	if oo and zz and (oz == 0) and (zo == 0):
		print(-1)
		continue
	if oo and zz == 0 and (oz == 0) and (zo == 0):
		print(0)
		continue
	if oo == 0 and zz and (oz == 0) and (zo == 0):
		print(0)
		continue
	if zo == oz:
		print(0)
		continue
	oo = 0
	zz = 0
	ss = set()
	sss = set()
	so = set()
	soo = set()
	for i in tt:
		if i[0][0] == '0' and i[0][-1] == '1':
			ss.add(i)
			sss.add(i[0])
		else:
			so.add(i)
			soo.add(i[0])
	tot = 0
	if oz < zo:
		ans = []
		while oz < zo - 1 and ss:
			s = ss.pop()
			if s[0][-1::-1] in soo:
				continue
			oz += 1
			zo -= 1
			ans.append(s[1] + 1)
			tot += 1
		if oz < zo - 1:
			print(-1)
		else:
			print(tot)
			ans.sort()
			print(*ans)
	else:
		ans = []
		while zo < oz - 1 and so:
			s = so.pop()
			if s[0][-1::-1] in sss:
				continue
			zo += 1
			oz -= 1
			tot += 1
			ans.append(s[1] + 1)
		if zo < oz - 1:
			print(-1)
		else:
			print(tot)
			ans.sort()
			print(*ans)


import os, sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		string = [input().strip() for _ in range(n)]
		dct = {}
		(fir, sec, tr, ty1) = (set(), set(), 0, 0)
		for (ind, i) in enumerate(string):
			if i[0] != i[-1]:
				tr += 1
				rev = i[::-1]
				z = dct.get(rev)
				if z:
					del dct[rev]
					if i[0] == '1':
						sec.remove(z)
					else:
						fir.remove(z)
				else:
					dct[i] = ind + 1
					if i[0] == '1':
						fir.add(ind + 1)
					else:
						sec.add(ind + 1)
			elif i[0] == '1':
				ty1 += 1
		if not tr:
			if n == ty1 or not ty1:
				print(0)
				print()
			else:
				print(-1)
			continue
		if len(fir) < len(sec):
			(fir, sec) = (sec, fir)
		(ans, ind, tt) = (0, [], len(sec))
		while len(fir) > tt + 1:
			ans += 1
			ind.append(fir.pop())
			tt += 1
		print(ans)
		print(*ind)
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()


from sys import stdin

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

def main():

	def solve():
		ww = []
		n = int(input())
		for _ in range(n):
			ww.append(input())
		wws = set(ww)
		sc1 = 0
		ec1 = 0
		m01 = 0
		m10 = 0
		rev10 = []
		rev01 = []
		for (i, w) in enumerate(ww):
			if w[0] == '1' and w[-1] == '1':
				sc1 += 1
				ec1 += 1
			elif w[0] == '1':
				sc1 += 1
				m10 += 1
				if w[::-1] not in wws:
					rev10.append(i + 1)
			elif w[-1] == '1':
				ec1 += 1
				m01 += 1
				if w[::-1] not in wws:
					rev01.append(i + 1)
		if sc1 > ec1:
			rc = (sc1 - ec1) // 2
			if rc <= len(rev10):
				print(rc)
				print(' '.join(map(str, rev10[:rc])))
			else:
				print(-1)
		elif ec1 > sc1:
			rc = (ec1 - sc1) // 2
			if rc <= len(rev01):
				print(rc)
				print(' '.join(map(str, rev01[:rc])))
			else:
				print(-1)
		elif sc1 == 0 or sc1 == n:
			print(0)
		elif m10 > 0 or m01 > 0:
			print(0)
		else:
			print(-1)
	q = int(input())
	for _ in range(q):
		solve()
main()


t = int(input())
for j in range(t):
	n = int(input())
	a = 0
	b = 0
	c = 0
	d = 0
	s = set()
	li = []
	for i in range(n):
		st = input()
		s.add(st)
		li.append(st)
		ans = []
		if st[0] == '0' and st[-1] == '0':
			a += 1
		if st[0] == '0' and st[-1] == '1':
			b += 1
		if st[0] == '1' and st[-1] == '0':
			c += 1
		if st[0] == '1' and st[-1] == '1':
			d += 1
	if b == 0 and c == 0:
		if a != 0 and d != 0:
			print('-1')
			continue
		print('0')
		continue
	else:
		if b > c:
			i = 0
			while i < len(li) and abs(b - c) > 1:
				if li[i][0] == '0' and li[i][-1] == '1':
					if li[i][::-1] not in s:
						b -= 1
						c += 1
						ans.append(i + 1)
				i += 1
		elif c > b:
			i = 0
			while i < len(li) and abs(c - b) > 1:
				if li[i][0] == '1' and li[i][-1] == '0':
					if li[i][::-1] not in s:
						b += 1
						c -= 1
						ans.append(i + 1)
				i += 1
		if abs(b - c) > 1:
			print('-1')
		else:
			print(len(ans))
			for i in ans:
				print(i, end=' ')
			print()


def reverse(s):
	str = ''
	for i in s:
		str = i + str
	return str
t = int(input())
for i in range(t):
	n = int(input())
	n00 = dict()
	n01 = dict()
	n10 = dict()
	n11 = dict()
	for j in range(n):
		s = input()
		if s[0] == '0' and s[-1] == '0':
			n00[s] = j + 1
		elif s[0] == '0' and s[-1] == '1':
			n01[s] = j + 1
		elif s[0] == '1' and s[-1] == '0':
			n10[s] = j + 1
		else:
			n11[s] = j + 1
	m00 = len(n00.keys())
	m01 = len(n01.keys())
	m10 = len(n10.keys())
	m11 = len(n11.keys())
	if m01 == 0 and m10 == 0:
		if m00 > 0 and m11 > 0:
			print(-1)
			continue
		else:
			print(0)
			print()
			continue
	if abs(m01 - m10) <= 1:
		print(0)
		print()
		continue
	diff = abs(m01 - m10)
	ch = diff // 2
	ans = list()
	if m01 > m10:
		ii = 0
		for tt in n01.keys():
			if ii < ch and reverse(tt) not in n10.keys():
				ans.append(n01[tt])
				ii += 1
	elif m10 > m01:
		ii = 0
		for tt in n10.keys():
			if ii < ch and reverse(tt) not in n01.keys():
				ans.append(n10[tt])
				ii += 1
	ans.sort()
	if len(ans) == diff // 2:
		print(len(ans))
		for x in range(len(ans)):
			print(ans[x], end=' ')
	else:
		print(-1, end=' ')
	print()


import heapq

def play(words):
	s01 = set()
	s10 = set()
	s11 = 0
	s00 = 0
	for w in words:
		if w[0] == '0':
			if w[-1] == '0':
				s00 += 1
			else:
				s01.add(w)
		elif w[-1] == '0':
			s10.add(w)
		else:
			s11 += 1
	if s11 > 0 and s00 > 0 and (len(s01) == 0) and (len(s10) == 0):
		print(-1)
		return
	diff = max(len(s01), len(s10)) - min(len(s01), len(s10))
	if diff <= 1:
		print(0)
		print('')
		return
	change = int(diff / 2)
	indices = []
	if len(s01) > len(s10):
		i = 0
		for w in words:
			i += 1
			if w[0] == '0' and w[-1] == '1':
				wr = w[::-1]
				if not wr in s10:
					indices.append(i)
			if len(indices) >= change:
				break
	else:
		i = 0
		for w in words:
			i += 1
			if w[0] == '1' and w[-1] == '0':
				wr = w[::-1]
				if not wr in s01:
					indices.append(i)
			if len(indices) >= change:
				break
	print(change)
	print(*indices)

def main():
	t = list(map(int, input().split()))[0]
	while t > 0:
		n = int(input())
		arr = []
		while n > 0:
			arr.append(input())
			n -= 1
		play(arr)
		t -= 1
main()


def solveOne():
	(zo, oz) = ([], [])
	exists = set()
	zero = one = zeroOne = oneZero = 0
	for (i, s) in enumerate(a):
		if s[0] == s[-1]:
			if s[0] == '0':
				zero += 1
			else:
				one += 1
			continue
		if s[0] == '0':
			zeroOne += 1
			zo.append(i)
		else:
			oneZero += 1
			oz.append(i)
		exists.add(hash(s))
	if zero > 0 and one > 0 and (zeroOne == oneZero == 0):
		return '-1'
	need = abs(zeroOne - oneZero) // 2
	if need == 0:
		return '0\n'
	ret = []
	count = need
	search = zo if zeroOne > oneZero else oz
	for i in search:
		if need == 0:
			return '%d\n%s' % (count, ' '.join(map(str, ret)))
		h = hash(a[i][::-1])
		if h not in exists:
			exists.add(h)
			ret.append(i + 1)
			need -= 1
	return '-1'
for _ in range(int(input())):
	n = int(input())
	a = [input().strip() for _ in range(n)]
	print(solveOne())


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

def oneLineArrayPrint(arr):
	print(' '.join([str(x + 1) for x in arr]))
t = int(input())
for _ in range(t):
	n = int(input())
	strings = []
	stringSet = set()
	for _ in range(n):
		s = input()
		strings.append(s)
		stringSet.add(s)
	aReversible = []
	bReversible = []
	has00 = False
	has11 = False
	aCnts = 0
	bCnts = 0
	for (i, s) in enumerate(strings):
		if s[0] == s[-1] == '0':
			has00 = True
		elif s[0] == s[-1] == '1':
			has11 = True
		elif s[0] == '0' and s[-1] == '1':
			aCnts += 1
			if s[::-1] not in stringSet:
				aReversible.append(i)
		else:
			bCnts += 1
			if s[::-1] not in stringSet:
				bReversible.append(i)
	if aCnts == bCnts == 0:
		if has00 and has11:
			print(-1)
		else:
			print(0)
			print()
	elif abs(aCnts - bCnts) <= 1:
		print(0)
		print()
	else:
		atemp = aCnts
		btemp = bCnts
		k1 = float('inf')
		ans1 = []
		for (i, idx) in enumerate(aReversible):
			ans1.append(idx)
			atemp -= 1
			btemp += 1
			if abs(atemp - btemp) <= 1:
				k1 = i + 1
				break
		atemp = aCnts
		btemp = bCnts
		k2 = float('inf')
		ans2 = []
		for (i, idx) in enumerate(bReversible):
			ans2.append(idx)
			atemp += 1
			btemp -= 1
			if abs(atemp - btemp) <= 1:
				k2 = i + 1
				break
		k = min(k1, k2)
		if k == float('inf'):
			print(-1)
		elif k1 < k2:
			print(k1)
			oneLineArrayPrint(ans1)
		else:
			print(k2)
			oneLineArrayPrint(ans2)


t = int(input())
for i in range(t):
	d = {'00': 0, '01': 0, '10': 0, '11': 0}
	set_10 = set()
	set_01 = set()
	set_10_strings = set()
	set_01_strings = set()
	index2string = []
	n = int(input())
	for string_num in range(n):
		s = input()
		index2string.append(s)
		key = s[0] + s[-1]
		if key == '01':
			set_01.add(string_num)
			set_01_strings.add(s)
		if key == '10':
			set_10.add(string_num)
			set_10_strings.add(s)
		d[key] += 1
	if d['00'] > 0 and d['11'] > 0 and (d['01'] == 0) and (d['10'] == 0):
		print(-1)
		continue
	if d['01'] > d['10']:
		bigger_set = set_01
		smaller_set = set_10_strings
	else:
		bigger_set = set_10
		smaller_set = set_01_strings
	bigger = max(d['01'], d['10'])
	smaller = min(d['01'], d['10'])
	ans = []
	while bigger - smaller > 1:
		for forward_string_index in bigger_set:
			break
		forward_string = index2string[forward_string_index]
		backward_string = forward_string[::-1]
		if backward_string in smaller_set:
			bigger_set.discard(forward_string_index)
			continue
		else:
			ans.append(str(forward_string_index + 1))
			bigger_set.discard(forward_string_index)
			bigger -= 2
	print(len(ans))
	print(' '.join(ans))


def solve():
	n = int(input())
	can_not = set()
	can_swap = []
	wait = {}
	flg_0 = False
	flg_2 = False
	for i in range(n):
		s = input()
		if s[0] == s[-1] and s[0] == '1':
			flg_2 = True
			can_not.add(2)
		elif s[0] == s[-1] and s[0] == '0':
			flg_0 = True
			can_not.add(0)
		elif s[0] != s[-1]:
			wait[s] = i
	num_0_1 = 0
	num_1_0 = 0
	type_ = [[], []]
	for s in wait:
		if s[::-1] in wait:
			can_not.add(1)
		elif s[0] == '0':
			num_0_1 += 1
			type_[0].append(wait[s])
		else:
			num_1_0 += 1
			type_[1].append(wait[s])
	if num_0_1 + num_1_0 == 0:
		if len(can_not) == 3:
			return (0, '')
		if 0 in can_not and 2 in can_not:
			return (-1, None)
		return (0, '')
	num = abs(num_0_1 - num_1_0) // 2
	if num == 0:
		return (0, '')
	else:
		typ = 0 if num_0_1 > num_1_0 else 1
		select = []
		for x in type_[typ][:num]:
			select.append(str(x + 1))
		return (num, ' '.join([x for x in select]))
for _ in range(int(input())):
	(num, ans) = solve()
	print(num)
	if ans is not None:
		print(ans)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
ti = int(input())
for i in range(100):
	pass
for _ in range(ti):
	cnt = 0
	ans = 0
	ssum = 0
	n = int(input())
	mp = {}
	s = []
	for i in range(100):
		pass
	for i in range(n):
		nn = str(input())
		s.append(nn)
		mp[nn] = i + 1
		if s[i][0] == '0' and s[i][len(s[i]) - 1] == '0':
			cnt += 1
		elif s[i][0] == '1' and s[i][len(s[i]) - 1] == '1':
			ans += 1
		else:
			ssum += 1
	for i in range(100):
		pass
	for i in range(100):
		pass
	if (cnt > 0 and ans > 0) and ssum == 0:
		print(-1)
	else:
		can_r = []
		cannot_r = []
		for i in range(n):
			ss = s[i]
			ss = ss[::-1]
			if ss[0] == ss[len(ss) - 1]:
				continue
			if ss not in mp:
				can_r.append(s[i])
		ol = 0
		lo = 0
		for x in can_r:
			if x[0] == '0':
				ol += 1
			else:
				lo += 1
		cnt = min(ol, lo)
		ol -= cnt
		lo -= cnt
		print(max(lo, ol) // 2)
		for x in can_r:
			if ol > 1 and x[0] == '0' and (x[len(x) - 1] == '1'):
				print(mp[x], end=' ')
				ol -= 2
			elif lo > 1 and x[0] == '1' and (x[len(x) - 1] == '0'):
				print(mp[x], end=' ')
				lo -= 2
	for i in range(100):
		pass


from collections import Counter, defaultdict
for _ in range(int(input())):
	n = int(input())
	z = defaultdict(list)
	v = []
	for i in range(n):
		s = input().strip()
		v.append(s)
		(x, y) = (int(s[0]), int(s[-1]))
		z[x, y].append(i)
	tt = set(v)
	if abs(len(z[0, 1]) - len(z[1, 0])) > 1:
		xx = abs(len(z[0, 1]) - len(z[1, 0])) // 2
		if len(z[0, 1]) > len(z[1, 0]):
			c = []
			for i in z[0, 1]:
				if v[i][::-1] not in tt:
					c.append(i + 1)
				if len(c) == xx:
					break
		else:
			c = []
			for i in z[1, 0]:
				if v[i][::-1] not in tt:
					c.append(i + 1)
				if len(c) == xx:
					break
		if len(c) == xx:
			print(xx)
			print(*c)
		else:
			print(-1)
	elif len(z[1, 1]) > 0 and len(z[0, 0]) > 0 and (len(z[0, 1]) == 0) and (len(z[1, 0]) == 0):
		print(-1)
	else:
		print(0)


from sys import stdin, stdout
for cs in range(int(stdin.readline())):
	n = int(stdin.readline())
	cnt = [[] for _ in range(4)]
	S = set()
	rev_hash = []
	for i in range(n):
		s = stdin.readline().strip()
		cnt[int(s[0]) * 2 + int(s[-1])].append(i)
		S.add(hash(s))
		rev_hash.append(hash(s[::-1]))
	if len(cnt[0] + cnt[3]) == n and len(cnt[0]) > 0 and (len(cnt[3]) > 0):
		stdout.write(f'-1\n')
	else:
		diff = len(cnt[1]) - len(cnt[2])
		if diff < 0:
			(cnt[1], cnt[2]) = (cnt[2], cnt[1])
			diff = abs(diff)
		diff //= 2
		ans = []
		for i in cnt[1]:
			if diff == 0:
				break
			if rev_hash[i] not in S:
				diff -= 1
				ans.append(i + 1)
		if diff != 0:
			stdout.write(f'-1\n')
		else:
			ans = [str(_) for _ in ans]
			stdout.write(f'{len(ans)}\n')
			stdout.write(' '.join(ans) + '\n')


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

class TreeNode:

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

class AvlTree:

	def __init__(self):
		self._tree = None

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

class SegmentTree1:

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

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

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

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

	def __len__(self):
		return self._len

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

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

class SegmentTree:

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

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

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

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

	def __len__(self):
		return self._len

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

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

class Factorial:

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

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

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

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

class Combination:

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

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

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

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

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

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

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

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	n = int(input())
	d = defaultdict(int)
	d1 = defaultdict(list)
	e = []
	for i in range(n):
		s = input()
		e.append(s)
		d[s[0] + s[-1]] += 1
		d1[s[0] + s[-1]].append(i)
	e1 = set(e)
	ans = 0
	if d['11'] > 0 and d['00'] > 0 and (d['01'] == 0) and (d['10'] == 0):
		print(-1)
		continue
	else:
		if d['01'] > d['10']:
			ans = -d['10'] + d['01']
			ans //= 2
			t = 0
		elif d['10'] > d['01']:
			ans = d['10'] - d['01']
			ans //= 2
			t = 1
		l = []
		u = 0
		i = 0
		while i < ans:
			if u == len(d1[str(t) + str(1 - t)]):
				break
			pos = d1[str(t) + str(1 - t)][u]
			if e[pos][::-1] not in e1:
				l.append(pos + 1)
				i += 1
			u += 1
		if len(l) != ans:
			print(-1)
			continue
		print(ans)
		print(*l, sep=' ')


import sys
input = sys.stdin.readline
Q = int(input())
Query = []
for _ in range(Q):
	N = int(input())
	Ss = [input().rstrip() for _ in range(N)]
	Query.append((N, Ss))
for (N, Ss) in Query:
	dic = {}
	A = [set() for _ in range(4)]
	Pair = 0
	for (i, S) in enumerate(Ss):
		if S[0] == '1' and S[-1] == '1':
			A[3].add(i)
		elif S[0] == '1' and S[-1] == '0':
			T = S[::-1]
			if T in dic.keys():
				Pair += 1
				A[1].remove(dic[T])
			else:
				dic[S] = i
				A[2].add(i)
		elif S[0] == '0' and S[-1] == '1':
			T = S[::-1]
			if T in dic.keys():
				Pair += 1
				A[2].remove(dic[T])
			else:
				dic[S] = i
				A[1].add(i)
		else:
			A[0].add(i)
	x1 = Pair + len(A[1])
	x2 = Pair + len(A[2])
	if x1 == x2 or x1 == x2 + 1 or x1 == x2 - 1:
		if x1 == 0 and x2 == 0 and (len(A[0]) > 0 and len(A[3]) > 0):
			print(-1)
		else:
			print(0)
			print()
	elif x1 > x2:
		must = (x1 - x2) // 2
		print(must)
		ans = []
		for a in A[1]:
			ans.append(a)
			if len(ans) == must:
				break
		print(' '.join([str(a + 1) for a in ans]))
	elif x2 > x1:
		must = (x2 - x1) // 2
		print(must)
		ans = []
		for a in A[2]:
			ans.append(a)
			if len(ans) == must:
				break
		print(' '.join([str(a + 1) for a in ans]))


from functools import reduce

def solve():
	n = int(input())
	words = []
	s01 = []
	s10 = []
	s00 = False
	s11 = False
	d1 = set()
	d2 = set()
	for i in range(n):
		ss = input()
		if ss[0] == '0' and ss[-1] == '0':
			s00 = True
		if ss[0] == '1' and ss[-1] == '1':
			s11 = True
		if ss[0] == '0' and ss[-1] == '1':
			s01.append(i)
			d1.add(ss)
		if ss[0] == '1' and ss[-1] == '0':
			s10.append(i)
			d2.add(ss)
		words.append(ss)
	if len(s01) == 0 and len(s10) == 0:
		if s00 == True and s11 == True:
			print(-1)
			return
		else:
			print(0, '')
			return
	chan = abs(len(s01) - len(s10)) // 2
	p = 0
	ans = []
	for i in range(chan):
		if len(s01) > len(s10):
			while words[s01[p]][::-1] in d2:
				if p < len(s01) - 1:
					p += 1
				else:
					print(-1)
					return
			ans.append(s01[p])
			p += 1
		else:
			while words[s10[p]][::-1] in d1:
				if p < len(s10) - 1:
					p += 1
				else:
					print(-1)
					return
			ans.append(s10[p])
			p += 1
	print(len(ans))
	for i in ans:
		print(i + 1, end=' ')
	print('')
t = int(input())
for i in range(t):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	ii = set()
	oo = set()
	io = set()
	oi = set()
	idx = {}
	for i in range(1, n + 1):
		ln = input().strip()
		idx[ln] = i
		x = (ln[0], ln[-1])
		if x == ('1', '1'):
			ii.add(ln)
		elif x == ('0', '0'):
			oo.add(ln)
		elif x == ('1', '0'):
			io.add(ln)
		elif x == ('0', '1'):
			oi.add(ln)
		else:
			raise Exception('SIW')
	if ii and oo and (not io and (not oi)):
		print(-1)
		continue
	off = io if len(io) > len(oi) else oi
	num = abs(len(io) - len(oi)) // 2
	y = num
	res = []
	for ll in off:
		if y == 0:
			break
		if ''.join(reversed(ll)) not in idx.keys():
			res.append(str(idx[ll]))
			y -= 1
	print(len(res))
	print(' '.join(res))


from sys import stdin

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

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

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

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

def same(a, b):
	return len(a) == len(b) and all([a[i] == b[-i - 1] for i in range(len(a))])
t = intput()
for _ in range(t):
	n = intput()
	words = []
	for i in range(1, n + 1):
		words.append((i, input()))
	maybe = []
	whybother = []
	justcant = []
	cand = []
	unique = {}
	for wordx in words:
		word = wordx[1]
		if word[0] == word[-1]:
			whybother.append(wordx)
		else:
			maybe.append(wordx)
			if word[0] == '1':
				sortedword = word[::-1]
			else:
				sortedword = word
			if sortedword not in unique:
				unique[sortedword] = 0
			unique[sortedword] += 1
	for wordx in maybe:
		word = wordx[1]
		if word[0] == '1':
			sortedword = word[::-1]
		else:
			sortedword = word
		if unique[sortedword] == 1:
			cand.append(wordx)
		else:
			justcant.append(wordx)
	typea = 0
	typeb = 0
	for wordx in justcant:
		if wordx[1][0] == '0':
			typea += 1
		else:
			typeb += 1
	typeaidx = []
	typebidx = []
	for wordx in cand:
		if wordx[1][0] == '0':
			typeaidx.append(wordx[0])
			typea += 1
		else:
			typebidx.append(wordx[0])
			typeb += 1
	if typea + typeb == 0:
		if all([wordx[1][0] == whybother[0][1][0] for wordx in whybother]):
			print(0)
			print()
		else:
			print(-1)
	elif typea - typeb > 1:
		cover = (typea - typeb) // 2
		print(cover)
		print(*typeaidx[:cover])
	elif typeb - typea > 1:
		cover = (typeb - typea) // 2
		print(cover)
		print(*typebidx[:cover])
	else:
		print(0)
		print()


import sys, math

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

def main():
	q = int(input())
	for _ in range(q):
		n = int(input())
		s = [str(input()) for k in range(n)]
		(a, b, c, d) = (0, 0, 0, 0)
		C = dict()
		D = dict()
		for k in range(n):
			e = s[k]
			if e[0] == '0' and e[-1] == '0':
				a += 1
			elif e[0] == '1' and e[-1] == '1':
				b += 1
			elif e[0] == '0' and e[-1] == '1':
				c += 1
				C[e] = k + 1
			else:
				d += 1
				D[e] = k + 1
		if c == d == 0 and a * b > 0:
			print(-1)
		else:
			diff = abs(c - d) // 2
			print(diff)
			if diff == 0:
				print('')
			else:
				ans = []
				if c > d:
					for e in C:
						if e[::-1] not in D:
							ans.append(C[e])
						if len(ans) == diff:
							break
				elif d > c:
					for e in D:
						if e[::-1] not in C:
							ans.append(D[e])
						if len(ans) == diff:
							break
				print(*ans)
main()


for _ in range(int(input())):
	n = int(input())
	s = [input() for i in range(n)]
	t = set(s)
	(a, b, c, d) = (set(), set(), set(), set())
	for i in range(n):
		if s[i][0] == '0':
			if s[i][-1] == '0':
				c.add(i)
			else:
				a.add(i)
		elif s[i][-1] == '0':
			b.add(i)
		else:
			d.add(i)
	l = set()
	for i in range(n):
		if (i in a or i in b) and s[i][::-1] in t:
			l.add(i)
	(la, lb, lc, ld, ll) = (len(a), len(b), len(c), len(d), len(l))
	if la == 0 and lb == 0:
		if lc == 0 or ld == 0:
			print(0)
		else:
			print(-1)
		continue
	if lb > la:
		if lb - ll // 2 < (lb - la) // 2 * 2:
			print(-1)
			continue
		x = (lb - la) // 2
		print(x)
		if x == 0:
			continue
		ans = []
		for i in b:
			if i not in l:
				ans.append(str(i + 1))
				x -= 1
				if x == 0:
					break
		print(' '.join(ans))
	elif la > lb:
		if la - ll // 2 < (la - lb) // 2 * 2:
			print(-1)
			continue
		x = (la - lb) // 2
		print(x)
		if x == 0:
			continue
		ans = []
		for i in a:
			if i not in l:
				ans.append(str(i + 1))
				x -= 1
				if x == 0:
					break
		print(' '.join(ans))
	else:
		print(0)


t = int(input().strip())
for _ in range(t):
	n = int(input().strip())
	ss = []
	match = {}
	t_00 = []
	t_01 = []
	t_10 = []
	t_11 = []
	for i in range(n):
		s = input().strip()
		ss.append(s)
		if s[::-1] in match:
			match[s[::-1]] = s
			match[s] = s[::-1]
		else:
			match[s] = None
		if len(s) > 1:
			if s[0] + s[-1] == '00':
				t_00.append(i)
			elif s[0] + s[-1] == '01':
				t_01.append(i)
			elif s[0] + s[-1] == '10':
				t_10.append(i)
			elif s[0] + s[-1] == '11':
				t_11.append(i)
		elif s == '0':
			t_00.append(i)
		elif s == '1':
			t_11.append(i)
	if (len(t_00) > 0 and len(t_01) == 0) and (len(t_11) > 0 and len(t_10) == 0):
		print(-1)
		continue
	diff = len(t_10) - len(t_01)
	if diff >= 0:
		if diff <= 1:
			print(0)
			print('')
			continue
		count = diff
		ps = []
		for p in t_10:
			if not match[ss[p]]:
				count -= 2
				ps.append(str(p + 1))
			if count <= 1:
				break
		if count <= 1:
			print(len(ps))
			print(' '.join(ps))
		else:
			print(-1)
	else:
		if -diff <= 1:
			print(0)
			print('')
			continue
		count = -diff
		ps = []
		for p in t_01:
			if not match[ss[p]]:
				count -= 2
				ps.append(str(p + 1))
			if count <= 1:
				break
		if count <= 1:
			print(len(ps))
			print(' '.join(ps))
		else:
			print(-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')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
	n = int(ri())
	(cnt00, cnt11, cnt01, cnt10) = (0, 0, 0, 0)
	lis01 = []
	lis10 = []
	(s01, s10) = (set(), set())
	for i in range(n):
		temp = ri()
		if temp[0] == temp[-1]:
			if temp[0] == '1':
				cnt11 += 1
			else:
				cnt00 += 1
		elif temp[0] == '1':
			lis10.append((i, temp))
			s10.add(temp)
			cnt10 += 1
		else:
			lis01.append((i, temp))
			s01.add(temp)
			cnt01 += 1
	if cnt10 == 0 and cnt01 == 0 and (cnt11 != 0) and (cnt00 != 0):
		print(-1)
	else:
		ans = []
		flag = True
		if cnt01 > cnt10:
			temp = 0
			while cnt01 > cnt10 + 1:
				while temp < len(lis01) and lis01[temp][1][::-1] in s10:
					temp += 1
				if temp >= len(lis01):
					flag = False
					break
				ans.append(lis01[temp][0] + 1)
				temp += 1
				cnt01 -= 1
				cnt10 += 1
		elif cnt10 > cnt01:
			temp = 0
			while cnt10 > cnt01 + 1:
				while temp < len(lis10) and lis10[temp][1][::-1] in s01:
					temp += 1
				if temp >= len(lis10):
					flag = False
					break
				ans.append(lis10[temp][0] + 1)
				temp += 1
				cnt10 -= 1
				cnt01 += 1
		if flag:
			print(len(ans))
			print(*ans)
		else:
			print(-1)


t = int(input())
for i in range(t):
	n = int(input())
	words = [input() for i in range(n)]
	s01 = []
	s10 = []
	set01 = set()
	set10 = set()
	s00 = False
	s11 = False
	for (i, word) in enumerate(words):
		if word[0] == '1' and word[-1] == '0':
			s10.append(i + 1)
			set10.add(word)
		if word[0] == '0' and word[-1] == '1':
			s01.append(i + 1)
			set01.add(word)
		if word[0] == '0' and word[-1] == '0':
			s00 = True
		if word[0] == '1' and word[-1] == '1':
			s11 = True
	s01c = len(s01)
	s10c = len(s10)
	if s01c + s10c == 0 and s00 and s11:
		print(-1)
		continue
	reverse = []
	try:
		while True:
			if abs(s01c - s10c) <= 1:
				break
			if s01c > s10c:
				i = s01.pop()
				while words[i - 1][::-1] in set10:
					i = s01.pop()
				s01c -= 1
				s10c += 1
				reverse.append(i)
			else:
				i = s10.pop()
				while words[i - 1][::-1] in set01:
					i = s10.pop()
				s01c += 1
				s10c -= 1
				reverse.append(i)
	except:
		print(-1)
	print(len(reverse))
	print(' '.join(map(str, reverse)))


t = int(input())
for _ in range(t):
	n = int(input())
	dic = {'01': [], '10': [], '11': [], '00': []}
	hash = {}
	bits = []
	for i in range(1, n + 1):
		s = input()
		hash[s] = 1
		bits.append(s)
		if s[0] == '0' and s[-1] == '1':
			dic['01'].append(i)
		elif s[0] == '1' and s[-1] == '0':
			dic['10'].append(i)
		elif s[0] == '1' and s[-1] == '1':
			dic['11'].append(i)
		else:
			dic['00'].append(i)
	a = len(dic['01'])
	b = len(dic['10'])
	c = len(dic['11'])
	d = len(dic['00'])
	res = 0
	if a == 0 and b == 0 and (c == 0 or d == 0):
		print(0)
		print('')
	elif a == 0 and b == 0:
		print(-1)
	else:
		if a > b:
			res = (a - b) // 2
			arr = []
			ind = 0
			for e in dic['01']:
				if ind == res:
					break
				rev = bits[e - 1][::-1]
				if rev not in hash or hash[rev] == 0:
					arr.append(e)
					hash[rev] = 1
					hash[bits[e - 1]] = 0
					ind += 1
		else:
			res = (b - a) // 2
			arr = []
			ind = 0
			for e in dic['10']:
				if ind == res:
					break
				rev = bits[e - 1][::-1]
				if rev not in hash or hash[rev] == 0:
					hash[rev] = 1
					hash[bits[e - 1]] = 0
					arr.append(e)
					ind += 1
		if ind < res:
			print(-1)
		else:
			print(res)
			print(*arr)


def f():
	n = int(input())
	word01 = dict()
	word10 = dict()
	have00 = 0
	have11 = 0
	for i in range(n):
		w = input()
		tag = w[0] + w[-1]
		if tag == '01':
			word01[w] = i
		elif tag == '10':
			word10[w] = i
		elif tag == '11':
			have11 = 1
		elif tag == '00':
			have00 = 1
	l01 = len(word01)
	l10 = len(word10)
	if l01 == 0 and l10 == 0:
		if have11 and have00:
			print(-1)
			return
	if l01 < l10:
		(word10, word01) = (word01, word10)
		(l10, l01) = (l01, l10)
	if l01 - l10 < 2:
		print(0)
		print()
		return
	count = (l01 - l10) // 2
	changeIndex = []
	for w in word01:
		if count <= 0:
			break
		if w[::-1] in word10:
			continue
		changeIndex.append(word01[w])
		count -= 1
	print(len(changeIndex))
	print(' '.join((str(s + 1) for s in changeIndex)))
t = int(input())
for i in range(t):
	f()


for cs in range(int(input())):
	n = int(input())
	cnt = [[] for _ in range(4)]
	S = set()
	rev_hash = []
	for i in range(n):
		s = input()
		cnt[int(s[0]) * 2 + int(s[-1])].append(i)
		S.add(hash(s))
		rev_hash.append(hash(s[::-1]))
	if len(cnt[0] + cnt[3]) == n and len(cnt[0]) > 0 and (len(cnt[3]) > 0):
		print(-1)
	else:
		diff = len(cnt[1]) - len(cnt[2])
		if diff < 0:
			(cnt[1], cnt[2]) = (cnt[2], cnt[1])
			diff = abs(diff)
		diff //= 2
		ans = []
		for i in cnt[1]:
			if diff == 0:
				break
			if rev_hash[i] not in S:
				diff -= 1
				ans.append(i + 1)
		if diff != 0:
			print(-1)
		else:
			print(len(ans))
			print(*ans)


def fastio():
	import sys
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from collections import defaultdict as dd
(t,) = I()
while t:
	t -= 1
	d = dd(int)
	idx = dd(list)
	(n,) = I()
	l = []
	all = dd(int)
	revc = dd(int)
	flag = 1
	for i in range(n):
		s = input()
		l.append(s)
	for i in range(n):
		s = l[i]
		if all[s] and all[s[::-1]]:
			flag = 0
		elif all[s] and (not all[s[::-1]]):
			s = s[::-1]
		all[s] += 1
		d[s[0] + s[-1]] += 1
		l[i] = s
	for i in range(n):
		s = l[i]
		if all[s] and (not all[s[::-1]]):
			revc[s[0] + s[-1]] += 1
			idx[s[0] + s[-1]].append(i)
	if not flag:
		print(-1)
		continue
	a = []
	ans = 0
	if d['00'] and d['11'] and (d['00'] + d['11'] == n):
		print(-1)
	elif abs(d['01'] - d['10']) > 1:
		diff = abs(d['10'] - d['01'])
		ok = '10'
		if d['01'] > d['10']:
			ok = '01'
		for i in range(revc[ok]):
			ans += 1
			a.append(idx[ok][i] + 1)
			if ans == diff // 2:
				break
		if ans != diff // 2:
			print(-1)
		else:
			print(ans)
			print(*a)
	else:
		print(0)
		print()


import sys

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

def input():
	return sys.stdin.readline().rstrip('\n')

def oint():
	return int(input())
t = oint()
for _ in range(t):
	n = oint()
	w = []
	d = dict()
	oo = 0
	zz = 0
	zo = 0
	oz = 0
	fail = 0
	cnt = 0
	ans = []
	for i in range(n):
		a = input()
		if a[0] == a[-1]:
			if a[0] == '0':
				zz = 1
			else:
				oo = 1
			continue
		if a in d:
			a = a[::-1]
			if a in d:
				print(-1)
				fail = 1
				break
		if a[0] == '0':
			d[a] = (i + 1, 1)
			zo += 1
		else:
			d[a] = (i + 1, 0)
			oz += 1
	if fail:
		continue
	if zz == 1 and oo == 1 and (len(d) == 0):
		print(-1)
		continue
	ok = 0
	if zo - oz > 1:
		for dd in d:
			if d[dd][1] == 1 and (not dd[::-1] in d):
				cnt += 1
				ans.append(d[dd][0])
				zo -= 1
				oz += 1
			if zo - oz <= 1:
				ok = 1
				break
		if ok == 0:
			print(-1)
			continue
	elif oz - zo > 1:
		for dd in d:
			if d[dd][1] == 0 and (not dd[::-1] in d):
				cnt += 1
				ans.append(d[dd][0])
				zo += 1
				oz -= 1
			if oz - zo <= 1:
				ok = 1
				break
		if ok == 0:
			print(-1)
			continue
	print(cnt)
	print(*ans)


def rev(l1, l2):
	m = (len(l1) - len(l2)) // 2
	if m == 0:
		return []
	torev = []
	for k in l1:
		if k[::-1] not in l2:
			torev.append(k)
	if len(torev) < m:
		return -1
	else:
		return torev[:m]
for _ in range(int(input())):
	n = int(input())
	oo = []
	zz = []
	zo = set()
	oz = set()
	ind = dict()
	for i in range(n):
		s = input()
		ind[s] = i + 1
		if s[0] == '0':
			if s[-1] == '0':
				zz.append(s)
			else:
				zo.add(s)
		elif s[-1] == '0':
			oz.add(s)
		else:
			oo.append(s)
	if len(oz) >= len(zo):
		strings = rev(oz, zo)
	else:
		strings = rev(zo, oz)
	if strings == -1:
		print(-1)
	elif len(oo) >= 1 and len(zz) >= 1 and (len(oz) + len(zo) == 0):
		print(-1)
	else:
		print(len(strings))
		print(' '.join([str(ind[x]) for x in strings]))


t = int(input())
for rwe in range(t):
	n = int(input())
	if n == 1:
		dup = input()
		print(0)
		print('')
	else:
		klasa = [[[] for i in range(2)] for j in range(2)]
		rev = {}
		for i in range(n):
			s = input()
			klasa[int(s[0])][int(s[-1])].append(s)
			rev[s] = i + 1
		wynik = abs(len(klasa[0][1]) - len(klasa[1][0])) // 2
		if len(klasa[0][0]) == n or len(klasa[1][1]) == n:
			print(0)
			print('')
		elif len(klasa[1][0]) >= len(klasa[0][1]):
			odp = []
			wi = len(klasa[1][0])
			nn = len(klasa[0][1])
			kl01 = set(klasa[0][1])
			dasie = 0
			for elt in klasa[1][0]:
				if wi - nn <= 1:
					dasie = 1
					break
				if elt[::-1] not in kl01:
					odp.append(rev[elt])
					wi -= 1
					nn += 1
			if dasie:
				print(wynik)
				print(*odp)
			else:
				print(-1)
		else:
			odp = []
			wi = len(klasa[0][1])
			nn = len(klasa[1][0])
			kl01 = set(klasa[1][0])
			dasie = 0
			for elt in klasa[0][1]:
				if wi - nn <= 1:
					dasie = 1
					break
				if elt[::-1] not in kl01:
					odp.append(rev[elt])
					wi -= 1
					nn += 1
			if dasie:
				print(wynik)
				print(*odp)
			else:
				print(-1)


for _ in range(int(input())):
	n = int(input())
	a = []
	b = []
	x = {}
	cou1 = 0
	cou2 = 0
	cou3 = 0
	cou4 = 0
	for i in range(n):
		s = input()
		b.append(s)
		x[s] = True
		a.append(s[0] + s[-1])
		if a[i] == '00':
			cou1 += 1
		elif a[i] == '11':
			cou2 += 1
		elif a[i] == '10':
			cou3 += 1
		else:
			cou4 += 1
	if cou4 + cou3 == 0:
		if cou1 > 0 and cou2 > 0:
			print(-1)
		else:
			print('0\n')
	elif cou4 + cou3 == 1:
		print('0\n')
	elif abs(cou4 - cou3) <= 1:
		print('0\n')
	else:
		ans = []
		if cou4 > cou3:
			for i in range(n):
				if a[i] == '01' and b[i][::-1] not in x:
					cou4 -= 1
					cou3 += 1
					ans.append(i + 1)
				if cou4 - cou3 <= 1:
					break
		elif cou4 < cou3:
			for i in range(n):
				if a[i] == '10' and b[i][::-1] not in x:
					cou4 += 1
					cou3 -= 1
					ans.append(i + 1)
				if cou3 - cou4 <= 1:
					break
		print(len(ans))
		print(*ans)


def main():
	N = int(input())
	for _ in range(N):
		L = int(input())
		S = [str(input()) for _ in range(L)]
		(a, b, c, d) = (0, 0, 0, 0)
		(C, D) = ({}, {})
		for k in range(L):
			e = S[k]
			if e[0] == '0' and e[-1] == '0':
				a += 1
			elif e[0] == '1' and e[-1] == '1':
				b += 1
			elif e[0] == '0' and e[-1] == '1':
				c += 1
				C[e] = k + 1
			else:
				d += 1
				D[e] = k + 1
		if c == d == 0 and a * b > 0:
			print(-1)
		else:
			diff = abs(c - d) // 2
			print(diff)
			if diff == 0:
				print('')
			else:
				res = []
				if c > d:
					for e in C:
						if e[::-1] not in D:
							res.append(C[e])
						if len(res) == diff:
							break
				else:
					for e in D:
						if e[::-1] not in C:
							res.append(D[e])
							if len(res) == diff:
								break
				print(*res)
main()


import sys
import math as mt
t = int(input())
for _ in range(t):
	n = int(input())
	d = {}
	l11 = []
	l10 = []
	l00 = []
	l01 = []
	for i in range(n):
		s = input()
		d[s] = 1
		if s[0] == '0' and s[-1] == '1':
			l01.append([s, i])
		if s[0] == '0' and s[-1] == '0':
			l00.append([s, i])
		if s[0] == '1' and s[-1] == '0':
			l10.append([s, i])
		if s[0] == '1' and s[-1] == '1':
			l11.append([s, i])
	ans = []
	diff = 0
	if len(l01) - 1 > len(l10):
		diff = len(l01) - len(l10)
		for i in range(len(l01)):
			if diff > 1:
				if d.get(l01[i][0][::-1], -1) == -1:
					ans.append(l01[i][1] + 1)
					diff -= 2
	if len(l10) - 1 > len(l01):
		diff = len(l10) - len(l01)
		for i in range(len(l10)):
			if diff > 1:
				if d.get(l10[i][0][::-1], -1) == -1:
					ans.append(l10[i][1] + 1)
					diff -= 2
	if len(l01) == 0 and len(l10) == 0:
		if len(l11) > 0 and len(l00) > 0:
			print(-1)
		else:
			print(0)
			print()
	elif abs(diff) <= 1:
		print(len(ans))
		print(*ans)
	else:
		print(-1)


t = int(input())
for nt in range(t):
	n = int(input())
	d = {'00': [], '01': [], '10': [], '11': []}
	order = {}
	alld = {}
	for i in range(n):
		s = input()
		alld[s] = 0
		order[s] = i
		if s[0] == '0' and s[-1] == '0':
			d['00'] = ['00']
		elif s[0] == '1' and s[-1] == '1':
			d['11'] = ['11']
		elif s[0] == '1' and s[-1] == '0':
			d['10'].append(s)
		else:
			d['01'].append(s)
	if len(d['00']) > 0 and len(d['11']) > 0 and (len(d['10']) == 0) and (len(d['01']) == 0):
		print(-1)
		continue
	elif len(d['01']) == len(d['10']):
		print(0)
		print()
		continue
	elif len(d['01']) > len(d['10']):
		rr = (len(d['01']) - len(d['10'])) // 2
		rev = []
		for i in d['01']:
			reverse = i[::-1]
			if reverse not in alld:
				rev.append(i)
			if len(rev) >= rr:
				break
		if len(rev) >= rr:
			print(rr)
			for i in range(rr):
				print(order[rev[i]] + 1, end=' ')
			print()
		else:
			print(-1)
	else:
		rr = (len(d['10']) - len(d['01'])) // 2
		rev = []
		for i in d['10']:
			reverse = i[::-1]
			if reverse not in alld:
				rev.append(i)
			if len(rev) >= rr:
				break
		if len(rev) >= rr:
			print(rr)
			for i in range(rr):
				print(order[rev[i]] + 1, end=' ')
			print()
		else:
			print(-1)


def ae(arr2, arr1, k):
	k //= 2
	cur = set(map(lambda x: arr[x], arr1))
	ans = []
	c = 0
	for e in arr2:
		s = arr[e][::-1]
		if s not in cur:
			ans.append(e + 1)
			c += 1
		if c == k:
			break
	if c < k:
		print(-1)
	else:
		print(k)
		print(*ans)

def solve():
	n = int(input())
	arr.clear()
	arr1 = []
	arr2 = []
	f = 0
	for i in range(n):
		a = input()
		if a[0] != a[-1]:
			if a[0] == '1':
				arr1.append(i)
			else:
				arr2.append(i)
		elif a[0] == '0' and f % 10 == 0:
			f += 1
		elif a[0] == '1' and f // 10 == 0:
			f += 10
		arr.append(a)
	k = abs(len(arr2) - len(arr1))
	if k > 1:
		if len(arr2) > len(arr1):
			ae(arr2, arr1, k)
		else:
			ae(arr1, arr2, k)
	elif len(arr2) == len(arr1) == 0 and f // 10 and f % 10:
		print(-1)
	else:
		print(0)
t = int(input())
arr = []
for _ in range(t):
	solve()


for t in range(int(input())):
	n = int(input())
	all_ones = False
	all_zeroes = False
	left = []
	right = []
	all_strings = set()
	answer = []
	for i in range(1, n + 1):
		s = input()
		if s[0] == '0' and s[-1] == '0':
			all_zeroes = True
		elif s[0] == '1' and s[-1] == '1':
			all_ones = True
		elif s[0] == '0' and s[-1] == '1':
			left.append((s, i))
			all_strings.add(s)
		else:
			right.append((s, i))
			all_strings.add(s)
	if len(left) > len(right):
		li = [left, right]
	else:
		li = [right, left]
	(a, b) = (len(li[0]), len(li[1]))
	success = False
	if a == 0:
		success = True
	for x in li[0]:
		if abs(a - b) <= 1:
			success = True
			break
		elif x[0][::-1] not in all_strings:
			answer.append(x[1])
			a -= 1
			b += 1
	if not success or (all_zeroes and all_ones and (a == 0) and (b == 0)):
		print(-1)
		continue
	print(len(answer))
	print(*answer)