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

Difficulty: HARD

Solutions:
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)


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


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


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


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, 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 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()


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


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)


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)