This is the easy version of the problem. The difference between the versions is the constraint on n and the required number of operations. You can make hacks only if all versions of the problem are solved.

There are two binary strings a and b of length n (a binary string is a string consisting of symbols 0 and 1). In an operation, you select a prefix of a, and simultaneously invert the bits in the prefix (0 changes to 1 and 1 changes to 0) and reverse the order of the bits in the prefix.

For example, if a=001011 and you select the prefix of length 3, it becomes 011011. Then if you select the entire string, it becomes 001001.

Your task is to transform the string a into b in at most 3n operations. It can be proved that it is always possible.

Input

The first line contains a single integer t (1≤ t≤ 1000) — the number of test cases. Next 3t lines contain descriptions of test cases.

The first line of each test case contains a single integer n (1≤ n≤ 1000) — the length of the binary strings.

The next two lines contain two binary strings a and b of length n.

It is guaranteed that the sum of n across all test cases does not exceed 1000.

Output

For each test case, output an integer k (0≤ k≤ 3n), followed by k integers p_1,…,p_k (1≤ p_i≤ n). Here k is the number of operations you use and p_i is the length of the prefix you flip in the i-th operation.

Example

Input


5
2
01
10
5
01011
11100
2
01
01
10
0110011011
1000110100
1
0
1


Output


3 1 2 1
6 5 2 5 3 1 2
0
9 4 1 2 10 4 1 2 1 5
1 1

Note

In the first test case, we have 01→ 11→ 00→ 10.

In the second test case, we have 01011→ 00101→ 11101→ 01000→ 10100→ 00100→ 11100.

In the third test case, the strings are already the same. Another solution is to flip the prefix of length 2, which will leave a unchanged.

Difficulty: EASY

Solutions:
def flip(arr_a, arr_b):
	ops = 0
	prefixlis = []
	lis_a = arr_a.copy()
	lis_b = arr_b.copy()
	while arr_a != arr_b:
		same = 0
		for i in range(-1, -len(arr_a) - 1, -1):
			if arr_a[i] == arr_b[i]:
				same += 1
			else:
				break
		if same >= 1:
			arr_a = arr_a[:len(arr_a) - same]
			arr_b = arr_b[:len(arr_b) - same]
		if arr_a == []:
			break
		if arr_a[0] == arr_b[-1]:
			prefixlis.append(1)
			prefixlis.append(len(arr_a))
			operation(arr_a, 1)
			operation(arr_a, len(arr_a))
			ops += 2
			if arr_a == arr_b:
				break
		else:
			prefixlis.append(len(arr_a))
			operation(arr_a, len(arr_a))
			ops += 1
			if arr_a == arr_b:
				break
	print(ops, end=' ')
	if ops == 0:
		return
	for i in range(ops):
		print(prefixlis[i], end=' ')

def operation(arr_a, prefix):
	for i in range(prefix):
		if arr_a[i] == '0':
			arr_a[i] = '1'
		else:
			arr_a[i] = '0'
	arr_a[:prefix] = arr_a[:prefix][::-1]
t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	b = input()
	arr_a = []
	for element in a:
		arr_a.append(element)
	arr_b = []
	for element in b:
		arr_b.append(element)
	if len(arr_a) == 1:
		if arr_a == arr_b:
			print(0)
		else:
			print(1, 1)
	else:
		flip(arr_a, arr_b)
		print()


def flip(a, i):
	p = [0] * i
	for j in range(i):
		if a[j] == 1:
			p[j] = 0
		else:
			p[j] = 1
	p.reverse()
	for i in range(i):
		a[i] = p[i]
	return a
t = int(input())
for _ in range(t):
	n = int(input())
	X = [int(i) for i in input()]
	Y = [int(i) for i in input()]
	k = []
	ans = 0
	for i in range(n - 1, -1, -1):
		if X[i] != Y[i]:
			if X[0] != Y[i]:
				k.append(i + 1)
				X = flip(X, i + 1)
				ans += 1
			else:
				k.append(1)
				k.append(i + 1)
				X = flip(X, 1)
				X = flip(X, i + 1)
				ans += 2
	print(ans, end=' ')
	for i in k:
		print(i, end=' ')
	print()


t = int(input())
while t != 0:
	n = int(input())
	a = list(input())
	b = list(input())
	ans = []
	st = 0
	en = n - 1
	inv_f = drn_f = 0
	count = 0
	j = n - 1
	while count < n:
		count += 1
		if inv_f == 0:
			if drn_f == 0:
				if a[en] == b[j]:
					en -= 1
					j -= 1
					pass
				elif a[st] != b[j]:
					ans.append(j)
					st += 1
					inv_f = 1
					drn_f = 1
					j -= 1
				else:
					ans.append(0)
					ans.append(j)
					st += 1
					inv_f = 1
					drn_f = 1
					j -= 1
			elif a[st] == b[j]:
				st += 1
				j -= 1
			elif a[en] != b[j]:
				ans.append(j)
				en -= 1
				j -= 1
				inv_f = 1
				drn_f = 0
			else:
				ans.append(0)
				ans.append(j)
				en -= 1
				j -= 1
				inv_f = 1
				drn_f = 0
		elif drn_f == 0:
			if a[en] != b[j]:
				en -= 1
				j -= 1
				pass
			elif a[st] == b[j]:
				ans.append(j)
				st += 1
				inv_f = 0
				drn_f = 1
				j -= 1
			else:
				ans.append(0)
				ans.append(j)
				st += 1
				inv_f = 0
				drn_f = 1
				j -= 1
		elif a[st] != b[j]:
			st += 1
			j -= 1
		elif a[en] == b[j]:
			ans.append(j)
			en -= 1
			j -= 1
			inv_f = 0
			drn_f = 0
		else:
			ans.append(0)
			ans.append(j)
			en -= 1
			j -= 1
			inv_f = 0
			drn_f = 0
	print(len(ans), end=' ')
	for i in range(len(ans)):
		print(ans[i] + 1, end=' ')
	print()
	t -= 1


import os
import sys
from io import BytesIO, IOBase

def operation(A, pos):
	for i in range(pos + 1):
		if A[i] == 1:
			A[i] = 0
		else:
			A[i] = 1
	(i, j) = (0, pos)
	while i < j:
		(A[i], A[j]) = (A[j], A[i])
		i += 1
		j -= 1

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = input()
		b = input()
		A = list()
		B = list()
		for i in range(n):
			A.append(int(a[i]))
			B.append(int(b[i]))
		k = 0
		p = list()
		for i in range(n - 1, 0, -1):
			if A[i] != B[i]:
				if A[0] != B[i]:
					k += 1
					p.append(i + 1)
					operation(A, i)
				else:
					k += 2
					if A[0] == 0:
						A[0] = 1
					else:
						A[0] = 0
					p.append(1)
					p.append(i + 1)
					operation(A, i)
		if A[0] != B[0]:
			A[0] = B[0]
			k += 1
			p.append(1)
		print(k, end=' ')
		for prefix in p:
			print(prefix, end=' ')
		print()
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 = lambda s: self.buffer.write(s.encode()) if self.writable else None

	def read(self):
		if self.buffer.tell():
			return self.buffer.read().decode('ascii')
		return os.read(self._fd, os.fstat(self._fd).st_size).decode('ascii')

	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().decode('ascii')

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

def print(*args, sep=' ', end='\n', file=sys.stdout, flush=False):
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(end)
	if flush:
		file.flush()
(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.setrecursionlimit(10000)
main()


import sys
t = int(input())
for _ in range(t):
	n = int(input())
	tempa = input()
	tempb = input()
	a = []
	for i in tempa:
		a.append(int(i))
	b = []
	for i in tempb:
		b.append(int(i))
	count = 0
	anslist = []
	for i in range(n - 1, -1, -1):
		if a[i] != b[i]:
			if a[0] != b[i]:
				anslist.append(i + 1)
				for j in range(i + 1):
					if a[j] == 0:
						a[j] = 1
					else:
						a[j] = 0
				a[0:i + 1] = reversed(a[0:i + 1])
				count += 1
			else:
				if a[0] == 0:
					a[0] = 1
				else:
					a[0] = 0
				anslist.append(1)
				for j in range(i + 1):
					if a[j] == 0:
						a[j] = 1
					else:
						a[j] = 0
				anslist.append(i + 1)
				a[0:i + 1] = reversed(a[0:i + 1])
				count += 2
	print(count, end=' ')
	for i in anslist:
		sys.stdout.write(str(i) + ' ')
	print()


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	o = []
	p = []
	l = []
	for i in range(n):
		o.append(a[i])
		p.append(b[i])
	for i in range(n - 1, -1, -1):
		if o[i] == p[i]:
			continue
		if o[0] == p[i]:
			l.append(1)
			if o[0] == '0':
				o[0] = '1'
			else:
				o[0] = '0'
		l.append(i + 1)
		for j in range(i + 1):
			if o[j] == '1':
				o[j] = '0'
			else:
				o[j] = '1'
		for j in range((i + 1) // 2):
			t = o[j]
			o[j] = o[i - j]
			o[i - j] = t
	print(len(l), end=' ')
	for k in range(len(l)):
		print(l[k], end=' ')
	print()


def reverse(end, arr):
	i = 0
	j = end
	while i < j:
		(arr[i], arr[j]) = (arr[j], arr[i])
		i += 1
		j -= 1

def flip(end, a):
	for i in range(end + 1):
		if a[i] == '0':
			a[i] = '1'
		else:
			a[i] = '0'

def solve(a, b, n, ans):
	moves = []
	end = n - 1
	while end >= 0:
		if a[end] != b[end]:
			if a[0] == a[end]:
				reverse(end, a)
				flip(end, a)
				moves.append(end + 1)
			else:
				reverse(0, a)
				flip(0, a)
				moves.append(1)
				reverse(end, a)
				flip(end, a)
				moves.append(end + 1)
		end -= 1
	ans.append(moves)

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


w = int(input())
for o in range(w):
	n = int(input())
	A = input()
	B = input()
	dp = list(map(int, list(A)))
	B = list(map(int, list(B)))
	count = 0
	ans = []
	for i in range(n - 1, -1, -1):
		if dp[i] != B[i]:
			if dp[0] != dp[i]:
				count += 1
				ans.append(1)
				dp[0] ^= 1
			count += 1
			ans.append(i + 1)
			(l, r) = (0, i)
			while l < r:
				(x, y) = (dp[l], dp[r])
				x ^= 1
				y ^= 1
				(dp[l], dp[r]) = (y, x)
				l += 1
				r -= 1
			if l == r:
				dp[l] ^= 1
	print(count, end=' ')
	for i in ans:
		print(i, end=' ')
	print()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = input().strip()
	b = input().strip()
	a = list(a)
	b = list(b)
	for i in range(0, n):
		if a[i] == '1':
			a[i] = 1
		else:
			a[i] = 0
		if b[i] == '0':
			b[i] = 0
		else:
			b[i] = 1
	ind = []
	k = 0
	for i in range(n - 1, 0, -1):
		if a[i] != b[i]:
			if a[0] == b[i]:
				k += 2
				ind.append(1)
				ind.append(i + 1)
				a[0] = a[0] ^ 1
			else:
				ind.append(i + 1)
				k += 1
			l = i
			c = i // 2
			for j in range(0, c + 1):
				if j == i - j:
					a[j] = a[j] ^ 1
					break
				tmp = a[j] ^ 1
				a[j] = a[i - j] ^ 1
				a[i - j] = tmp
	if a[0] != b[0]:
		ind.append(1)
		k += 1
	print(k, end=' ')
	for i in range(0, len(ind)):
		print(ind[i], end=' ')
	print()


def solve(a, b, n):
	i = n - 1
	res = []
	while i >= 0 and a[:i + 1] != b[:i + 1]:
		if b[i] != a[i]:
			if b[i] == a[0]:
				a = flip(a, 1)
				res.append(1)
			a = flip(a, i + 1)
			res.append(i + 1)
		i = i - 1
	print(len(res), end=' ')
	for i in res:
		print(i, end=' ')
	print()

def flip(a, n):
	part = a[:n]
	new = ''
	for i in part:
		if i == '1':
			new += '0'
		else:
			new += '1'
	return new[::-1] + a[n:]
for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	solve(a, b, n)


import sys
input = sys.stdin.readline
t = int(input())
for t1 in range(t):
	n = int(input())
	a1 = input()
	a1 = a1.strip()
	b1 = input()
	b1 = b1.strip()
	c = 0
	a = []
	b = []
	for i in range(n):
		a.append(int(a1[i]))
		b.append(int(b1[i]))
	ans = []
	for i in range(n - 1, -1, -1):
		if a[i] != b[i]:
			if a[0] != b[i]:
				for j in range(i + 1):
					a[j] = a[j] ^ 1
				a = a[:i + 1][::-1] + a[i + 1:]
				ans.append(i + 1)
			else:
				a[0] = b[i] ^ 1
				for j in range(i + 1):
					a[j] = a[j] ^ 1
				z = a[:i + 1]
				z = z[::-1]
				a = z + a[i + 1:]
				ans.append(1)
				ans.append(i + 1)
	s = ''
	for i in ans:
		s += str(i) + ' '
	print(len(ans), s)


test = False

def get_end(start, end, reversed):
	if not reversed:
		return end
	else:
		return start

def get_start(start, end, reversed):
	if not reversed:
		return start
	else:
		return end

def invert(bit, inverted):
	if not inverted:
		return bit
	else:
		return not bit
t = int(input())
for test_case in range(t):
	n = int(input())
	a = list(map(lambda x: bool(int(x)), input()))
	b = list(map(lambda x: bool(int(x)), input()))
	(start, end) = (0, n - 1)
	(reversed, inverted) = (False, False)
	instr = ''
	k = 0
	for m in range(n - 1, -1, -1):
		target = b[m]
		real_m_in_a = get_end(start, end, reversed)
		cand = invert(a[real_m_in_a], inverted)
		if cand == target:
			if not reversed:
				end -= 1
			else:
				start += 1
		else:
			first_index = get_start(start, end, reversed)
			cand = invert(a[first_index], inverted)
			if (not cand) != target:
				instr += '1 '
				k += 1
			instr += str(m + 1) + ' '
			k += 1
			reversed = not reversed
			inverted = not inverted
			if not reversed:
				end -= 1
			else:
				start += 1
	print(k, instr)


import math

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

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

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

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

def chnge(a):
	b = a[:]
	for i in range(len(a)):
		if a[i] == '1':
			b[-i - 1] = '0'
		else:
			b[-i - 1] = '1'
	return b
t = ii()
for _ in range(t):
	n = ii()
	a = list(input())
	b = list(input())
	i = n - 1
	ans = []
	while i >= 0:
		if a[i] == b[i]:
			i -= 1
			continue
		if a[0] != b[i]:
			a = chnge(a[:i + 1]) + a[i + 1:]
			ans.append(i + 1)
		else:
			ans.append(1)
			a = chnge(a[:1]) + a[1:]
			ans.append(i + 1)
			a = chnge(a[:i + 1]) + a[i + 1:]
	print(len(ans), end=' ')
	for i in ans:
		print(i, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	l = []
	while a != b:
		x = ''
		if b[n - 1] == a[n - 1]:
			n = n - 1
			continue
		elif b[n - 1] != a[0]:
			for i in range(n):
				if a[n - i - 1] == '0':
					x += '1'
				else:
					x += '0'
			l.append(n)
			a = x + a[n:]
			n = n - 1
		else:
			if a[0] == '1':
				a = '0' + a[1:]
			else:
				a = '1' + a[1:]
			l.append(1)
			for i in range(n):
				if a[n - i - 1] == '0':
					x += '1'
				else:
					x += '0'
			a = x + a[n:]
			l.append(n)
			n = n - 1
	print(len(l), sep=' ', end=' ')
	for i in l:
		print(i, sep=' ', end=' ')
	print(sep='')