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
Tags: String algorithms

Data structures

Constructive algorithms
Skill types: Data structures

Starter code:

Solutions:
from collections import defaultdict as dd
import sys
input = sys.stdin.readline
t = int(input())
while t:
	n = int(input())
	a = list(map(int, input().strip()))
	b = list(map(int, input().strip()))
	j = n - 1
	ans = []
	while j >= 0:
		while j >= 0 and b[j] == a[j]:
			j -= 1
		if j >= 0 and a[0] == b[j]:
			a[0] = 1 - a[0]
			ans.append(1)
		if j % 2 == 1:
			k = j // 2 + 1
		else:
			k = j // 2
			if j >= 0 and j % 2 == 0:
				a[j // 2] = 1 - a[j // 2]
		for i in range(k):
			(a[i], a[j - i]) = (1 - a[j - i], 1 - a[i])
		if j >= 0:
			ans.append(j + 1)
		j -= 1
	print(len(ans), *ans)
	t -= 1


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


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	A = []
	Ans = []
	for i in range(len(s1)):
		A.append(int(s1[i]))
	for i in range(len(s1) - 1, -1, -1):
		if A[i] != int(s2[i]):
			if A[i] != A[0]:
				Ans.append(1)
				A[0] = 1 - A[0]
				Ans.append(i + 1)
				for j in range((i + 1) // 2):
					(A[j], A[i - j]) = (1 - A[i - j], 1 - A[j])
				if i % 2 == 0:
					A[i // 2] = 1 - A[i // 2]
			else:
				Ans.append(i + 1)
				for j in range((i + 1) // 2):
					(A[j], A[i - j]) = (1 - A[i - j], 1 - A[j])
				if i % 2 == 0:
					A[i // 2] = 1 - A[i // 2]
	print(len(Ans), end=' ')
	print(*Ans)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
from collections import Counter
from bisect import bisect_left, bisect_right
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007

def flip(a, i):
	for j in range(i):
		if a[j] == '1':
			a[j] = '0'
		else:
			a[j] = '1'
	a = a[:i][::-1] + a[i:]
	return a
tc = ii1()
for _ in range(tc):
	n = ii1()
	(a, b) = (list(is1()), list(is1()))
	res = []
	i = n - 1
	while i > 0:
		if a[i] != b[i]:
			if a[0] == b[i]:
				res.append(1)
				a[0] = '0' if a[0] == '1' else '1'
			res.append(i + 1)
			a = flip(a, i + 1)
		i -= 1
	if a[0] != b[0]:
		res.append(1)
	print(len(res), *res)


t = int(input())
for _ in range(t):
	y = int(input())
	f = 0
	a = input()
	b = input()
	a = list(a)
	b = list(b)
	z = []
	for q in range(y):
		if a[q] != b[q] and q == 0:
			f = f + 1
			z.append(1)
		elif q != 0 and a[q] != b[q]:
			z.append(q + 1)
			f = f + 1
			z.append(1)
			f = f + 1
			z.append(q + 1)
			f = f + q + 1
	print(len(z), *z)


def op(s, end):
	l = []
	for i in range(end, -1, -1):
		if s[i] == '0':
			l.append('1')
		else:
			l.append('0')
	return l

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = list(input())
		b = list(input())
		o = []
		z = n - 1
		while z >= 0:
			if a[z] == b[z]:
				z -= 1
				continue
			if a[0] != b[z]:
				o.append(z + 1)
				a = op(a, z)
				z -= 1
			else:
				o.append('1')
				a[0] = '1' if a[0] == '0' else '0'
		print(len(o), *o)
main()


for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	a = list(a)
	b = list(b)
	d = []
	e = 0
	i = 0
	while a != b:
		if a[i] != b[i]:
			c = a[:i + 1]
			del a[:i + 1]
			e += 1
			d.append(i + 1)
			d.append(1)
			d.append(i + 1)
			for j in range(len(c)):
				if c[j] == '0':
					c[j] = '1'
				else:
					c[j] = '0'
			c.reverse()
			if c[0] == '0':
				c[0] = '1'
			else:
				c[0] = '0'
			for j in range(len(c)):
				if c[j] == '0':
					c[j] = '1'
				else:
					c[j] = '0'
			c.reverse()
			a = c + a
		else:
			i += 1
	print(3 * e, *d)


from fractions import Fraction
from collections import defaultdict
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

def input():
	return sys.stdin.readline().rstrip('\r\n')
t = int(input())
for _ in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	if s1 == s2:
		print('0')
	else:
		s1 = list(s1)
		s2 = list(s2)
		last = n - 1
		r = []
		while last >= 0:
			if s1[last] == s2[last]:
				last -= 1
			elif s1[0] != s2[last]:
				r.append(last + 1)
				tmp = list(s1)
				for i in range(last + 1):
					tmp[i] = chr(1 - (ord(s1[last - i]) - 48) + 48)
				for i in range(last + 1):
					s1[i] = tmp[i]
			else:
				r.append(1)
				s1[0] = chr(1 - (ord(s1[0]) - 48) + 48)
		print(len(r), end=' ')
		for i in r:
			print(i, end=' ')
		print()


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

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

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))
MOD = 1000000007
PMOD = 998244353
T = 1
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = list(stdin.readline().strip('\n'))
	b = list(stdin.readline().strip('\n'))
	c = a[0]
	ans = []
	for i in range(1, n):
		if a[i] != a[i - 1]:
			ans.append(i)
			c = a[i]
	for i in range(n - 1, -1, -1):
		if b[i] != c:
			ans.append(i + 1)
			c = b[i]
	print(len(ans), *ans)


def solve():
	n = int(input())
	a = input()
	b = input()
	ans = []
	for i in range(n):
		if a[i] != b[i]:
			ans.extend([i + 1, 1, i + 1])
	print(len(ans), ' '.join((str(v) for v in ans)))
t = int(input())
for _ in range(t):
	solve()


def func(n, c1, c2):
	output = []
	n = [i for i in range(1, n + 1)]
	zipped = zip(n, c1, c2)
	for i in zipped:
		if i[1] != i[2]:
			output.append(str(i[0]))
			output.append(str(1))
			output.append(str(i[0]))
	output.insert(0, str(len(output)))
	return ' '.join(output)

def main():
	for i in range(int(input())):
		n = int(input())
		c1 = input()
		c2 = input()
		print(func(n, c1, c2))
main()


import math, sys, bisect, heapq
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def inv(A):
	B = []
	for i in range(len(A) - 1, -1, -1):
		if A[i] == '1':
			B.append('0')
		else:
			B.append('1')
	return B
for _ in range(int(input())):
	N = int(input())
	A = [*input()]
	B = [*input()]
	Ans = []
	for i in range(N - 1, -1, -1):
		if A[i] != B[i]:
			if A[0] == A[i]:
				A = inv(A[:i + 1]) + A[i + 1:]
				Ans.append(i + 1)
			else:
				if A[0] == '1':
					A[0] = '0'
				else:
					A[0] = '1'
				Ans.append(1)
				A = inv(A[:i + 1]) + A[i + 1:]
				Ans.append(i + 1)
	n = len(Ans)
	Ans = [n] + Ans
	print(*Ans)


t = int(input())

def out(s1, s2):
	dif = []
	for i in range(n):
		if s1[i] != s2[i]:
			dif.append(i)
	dif.reverse()
	print(3 * len(dif), end=' ')
	for i in dif:
		print(i + 1, 1, i + 1, end=' ')
	print()
while t:
	n = int(input())
	s1 = input()
	s2 = input()
	out(s1, s2)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	ans = []
	for i in range(n):
		if a[i] != b[i]:
			ans.append(i + 1)
			ans.append(1)
			ans.append(i + 1)
	print(len(ans), *ans)


I = input
for _ in [0] * int(I()):
	I()
	i = 0
	r = []
	for (x, y) in zip(I(), I()):
		i += 1
		if x != y:
			r += (i, 1, i)
	print(len(r), *r)


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


def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = len(li) - 1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans

def sieve_of_eratosthenes(n):
	ans = []
	arr = [1] * (n + 1)
	(arr[0], arr[1], i) = (0, 0, 2)
	while i * i <= n:
		if arr[i] == 1:
			j = i + i
			while j <= n:
				arr[j] = 0
				j += i
		i += 1
	for k in range(n):
		if arr[k] == 1:
			ans.append(k)
	return ans

def nc2(x):
	if x == 1:
		return 0
	else:
		return x * (x - 1) // 2

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def mex(li):
	check = [0] * 1001
	for i in li:
		check[i] += 1
	for i in range(len(check)):
		if check[i] == 0:
			return i

def sumdigits(n):
	ans = 0
	while n != 0:
		ans += n % 10
		n //= 10
	return ans

def product(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def maxpower(n, k):
	cnt = 0
	while n > 1:
		cnt += 1
		n //= k
	return cnt
from math import *
from collections import deque
max_steps = 100005
for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	a = [int(x) for x in list(s1)]
	b = [int(x) for x in list(s2)]
	ans = []
	for i in range(1, n):
		if a[i] != a[i - 1]:
			ans.append(i)
	if a[n - 1] != b[n - 1]:
		ans.append(n)
	temp = []
	for i in range(1, n):
		if b[i] != b[i - 1]:
			temp.append(i)
	ans += temp[::-1]
	print(len(ans), *ans)


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	ans = []
	for i in range(n - 1, -1, -1):
		if a[i] == b[i]:
			pass
		elif a[0] == b[i]:
			ans.append(1)
			if a[0] == '1':
				a = '0' + a[1:]
			else:
				a = '1' + a[1:]
			s1 = ''
			for j in range(0, i + 1):
				if a[j] == '1':
					s1 += '0'
				else:
					s1 += '1'
			if i == n - 1:
				a = s1[::-1]
			else:
				a = s1[::-1] + a[i + 1:]
			ans.append(i + 1)
		else:
			s1 = ''
			for j in range(0, i + 1):
				if a[j] == '1':
					s1 += '0'
				else:
					s1 += '1'
			if i == n - 1:
				a = s1[::-1]
			else:
				a = s1[::-1] + a[i + 1:]
			ans.append(i + 1)
	print(len(ans), *ans)


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	a1 = list(a)
	b1 = list(b)
	t = 0
	x = []
	j = n - 1
	while j >= 0:
		if a1[j] == b1[j]:
			j -= 1
		elif int(a1[0]) ^ 1 == int(b1[j]):
			t += 1
			x.append(j + 1)
			for i in range(n):
				a1[i] = str(int(a1[i]) ^ 1)
			for k in range((j + 1) // 2):
				(a1[k], a1[j - k]) = (a1[j - k], a1[k])
			j -= 1
		else:
			t += 2
			x.append(1)
			a1[0] = str(int(a1[0]) ^ 1)
			x.append(j + 1)
			for i in range(n):
				a1[i] = str(int(a1[i]) ^ 1)
			for k in range((j + 1) // 2):
				(a1[k], a1[j - k]) = (a1[j - k], a1[k])
			j -= 1
	print(t, end=' ')
	print(*x)


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


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
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')
testcases = int(input())
for j in range(testcases):
	n = int(input())
	vala = [int(s) for s in input()]
	valb = [int(s) for s in input()]
	outy = []
	for s in range(n - 1, -1, -1):
		if vala[s] == valb[s]:
			continue
		elif vala[0] != valb[s]:
			for b in range(s + 1):
				vala[b] += 1
				vala[b] = vala[b] % 2
			for b in range(s // 2 + 1):
				(vala[b], vala[s - b]) = (vala[s - b], vala[b])
			outy.append(s + 1)
		else:
			vala[0] += 1
			vala[0] = vala[0] % 2
			outy.append(1)
			for b in range(s + 1):
				vala[b] += 1
				vala[b] = vala[b] % 2
			for b in range(s // 2 + 1):
				(vala[b], vala[s - b]) = (vala[s - b], vala[b])
			outy.append(s + 1)
	if len(outy) > 0:
		outy = [len(outy)] + outy
		print(*outy)
	else:
		print(0)


def aa(a):
	b = []
	for i in a:
		if i == '1':
			b.append('0')
		else:
			b.append('1')
	return reversed(b)
for _ in range(int(input())):
	n = int(input())
	A = input()
	B = input()
	a = []
	b = []
	for i in A:
		a.append(i)
	for i in B:
		b.append(i)
	c = []
	for i in range(n - 1, -1, -1):
		if b[i] == '1':
			if a[0] == '1':
				c.append(1)
				c.append(i + 1)
				a[0] = '0'
				a[:i + 1] = aa(a[:i + 1])
			else:
				c.append(i + 1)
				a[:i + 1] = aa(a[:i + 1])
		elif a[0] == '0':
			c.append(1)
			c.append(i + 1)
			a[0] = '1'
			a[:i + 1] = aa(a[:i + 1])
		else:
			c.append(i + 1)
			a[:i + 1] = aa(a[:i + 1])
	print(len(c), end=' ')
	for i in c:
		print(i, end=' ')
	print()


import sys
import math
input = sys.stdin.readline

def flip(plen):
	preffix = [1 - bit for bit in A[:plen]]
	A[:plen] = reversed(preffix)
T = int(input())
for t in range(T):
	N = int(input())
	A = list(map(int, input().strip()))
	B = list(map(int, input().strip()))
	flips = []
	i = N - 1
	while i >= 0:
		if A[i] == B[i]:
			i -= 1
			continue
		if 1 - A[0] == B[i]:
			flip(i + 1)
			flips.append(i + 1)
		else:
			flip(1)
			flip(i + 1)
			flips.append(1)
			flips.append(i + 1)
		i -= 1
	if flips:
		print(len(flips), end=' ')
		print(' '.join(map(str, flips)))
	else:
		print(0)


from functools import lru_cache
from sys import stdin, stdout
import sys
from math import *
for __ in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	ans = []
	x = 0
	y = n - 1
	while y >= 0:
		if a[y] == b[y]:
			y -= 1
		elif a[x] != a[y]:
			ans.append(1)
			if a[x] == '0':
				a[x] = '1'
			else:
				a[x] = '0'
		else:
			ans.append(y + 1)
			for i in range(y + 1):
				if a[i] == '1':
					a[i] = '0'
				else:
					a[i] = '1'
			a = a[:y + 1][::-1] + a[y + 1:]
	if len(ans) == 0:
		print(0)
	else:
		print(len(ans), end=' ')
		print(*ans)


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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

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

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

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

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

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

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

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

def main():
	for _ in range(N()):
		n = N()
		a = list(input())
		b = list(input())
		res = []

		def c(ind):
			for i in range(ind):
				a[i] = str(int(str(a[i])) ^ 1)
			a[:ind] = a[:ind][::-1]
		for i in range(n - 1, -1, -1):
			if a[i] == b[i]:
				continue
			if a[0] == b[i]:
				res.append(1)
				c(1)
				res.append(i + 1)
				c(i + 1)
			else:
				res.append(i + 1)
				c(i + 1)
		print(len(res), *res)
main()


for _ in range(int(input())):
	n = int(input())
	arr = [w for w in input()]
	b = [w for w in input()]
	i = n - 1
	ans = []
	res = 0
	while i >= 0:
		if arr[0] == b[i]:
			if arr[0] == '1':
				arr[0] = '0'
			else:
				arr[0] = '1'
			ans.append(1)
			p = arr[0:i + 1]
			x = []
			ans.append(i + 1)
			for item in p:
				if item == '1':
					x.append('0')
				else:
					x.append('1')
			x.reverse()
			arr = x + arr[i + 1:]
			res = res + 2
		else:
			p = arr[0:i + 1]
			x = []
			ans.append(i + 1)
			for item in p:
				if item == '1':
					x.append('0')
				else:
					x.append('1')
			x.reverse()
			arr = x + arr[i + 1:]
			res = res + 1
		i = i - 1
	print(res, end=' ')
	for item in ans:
		print(item, end=' ')
	print('')


for _ in range(int(input())):
	n = int(input())
	a = str(input())
	b = str(input())
	alst = []
	count = 0
	while n:
		if b[n - 1] == a[n - 1]:
			n -= 1
			a = a[:n]
			b = b[:n]
		elif b[n - 1] == a[0]:
			alst.append(1)
			alst.append(n)
			count += 2
			t = ''
			for i in a[1:][::-1]:
				t += str(int(i) ^ 1)
			a = t
			n -= 1
			b = b[:n]
		else:
			count += 1
			alst.append(n)
			t = ''
			for i in a[1:][::-1]:
				t += str(int(i) ^ 1)
			a = t
			n -= 1
			b = b[:n]
	print(count, *alst)


z = input
mod = 10 ** 9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0:
			return 0
	return 1
num = int(z())
for _ in range(num):
	n = int(z())
	l1 = list(z())
	l2 = list(z())
	c = 0
	lp = []
	j = 0
	ans = 0
	lp = []
	for i in l1:
		if i != l2[j]:
			ans = j
			lp.append(ans + 1)
			ans = 1
			lp.append(ans)
			lp.append(j + 1)
			c += 1
		j += 1
	print(c * 3, *lp)


import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
input = stdin.readline
letters = ascii_letters[:26]
for _ in range(int(input())):
	n = int(input())
	first = list(input().strip())
	second = list(input().strip())
	res = []
	for i in range(n - 1, -1, -1):
		if (n - 1 - i) % 2:
			x = '0' if first[i + (n - i) // 2] == '1' else '1'
		else:
			x = first[(n - 1 - i) // 2]
		if i == 0:
			if x != second[i]:
				res.append(1)
			continue
		if x != second[i]:
			res.append(i + 1)
		else:
			res.append(1)
			res.append(i + 1)
	print(len(res), *res)


t = int(input().strip(' '))
for i in range(t):
	n = int(input().strip(' '))
	a = input().strip(' ')
	b = input().strip(' ')
	s = ''
	x = 0
	for (i, j) in enumerate(a):
		if j != b[i]:
			if i == 0:
				s = str(1) + ' '
				x = x + 1
			else:
				s = s + str(i + 1) + ' ' + str(1) + ' ' + str(i + 1) + ' '
				x = x + 3
	ans = str(x) + ' ' + s
	print(ans.strip(' '))


import sys

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')
INF = 10 ** 19
MOD = 10 ** 9 + 7
for _ in range(INT()):
	N = INT()
	S = list(map(int, input()))
	T = list(map(int, input()))
	ans = []
	r = N
	for i in range(N):
		if S[0] != T[-1]:
			ans.append(r)
			for i in range(len(S)):
				S[i] ^= 1
			S = S[::-1]
			S.pop()
			T.pop()
			r -= 1
		else:
			if len(S) == 1:
				break
			ans.append(1)
			S[0] ^= 1
			ans.append(r)
			for i in range(len(S)):
				S[i] ^= 1
			S = S[::-1]
			S.pop()
			T.pop()
			r -= 1
	ans.insert(0, len(ans))
	print(*ans)


def prefix_flip(index, arr):
	s = []
	for j in range(index - 1, -1, -1):
		s.append(str(int(arr[j]) ^ 1))
	s.extend(arr[index:])
	return s
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(input())
	b = list(input())
	answer = []
	for i in range(n - 1, -1, -1):
		if b[i] == a[i]:
			continue
		elif b[i] == a[0]:
			answer.append(1)
			answer.append(i + 1)
			a[0] = str(int(a[0]) ^ 1)
			a = prefix_flip(i + 1, a)
		else:
			answer.append(i + 1)
			a = prefix_flip(i + 1, a)
	print(len(answer), *answer)


t = int(input())
for u in range(t):
	n = int(input())
	x = input()
	y = input()
	a = []
	b = []
	for i in x:
		a.append(True if i == '1' else False)
	for j in y:
		b.append(True if j == '1' else False)
	ans = []
	for i in range(n - 1, -1, -1):
		if a[i] != b[i]:
			if a[0] != b[i]:
				ans.append(i + 1)
				temp = a[:]
				for j in range(i, -1, -1):
					a[j] = not temp[i - j]
			else:
				ans.append(1)
				a[0] = not a[0]
				temp = a[:]
				for j in range(i, -1, -1):
					a[j] = not temp[i - j]
				ans.append(i + 1)
	print(len(ans), *ans)


for _ in range(int(input())):
	n = int(input())
	s = input()
	s1 = input()
	ans = []
	for i in range(n):
		if s[i] != s1[i]:
			ans.append(i)
	print(3 * len(ans), end=' ')
	for j in ans:
		print(j + 1, 1, j + 1, end=' ')
	print()


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
sys.setrecursionlimit(int(100000.0))
t = int(input())
while t:
	t -= 1
	n = int(input())
	s1 = input().strip()
	s2 = input().strip()
	cnt = 0
	for i in range(n):
		if s1[i] != s2[i]:
			cnt += 1
	if cnt:
		print(3 * cnt, end=' ')
		for i in range(n):
			if s1[i] != s2[i]:
				print(i + 1, 1, i + 1, end=' ')
		print()
	else:
		print(0)


def flip(a):
	for i in range(len(a)):
		if a[i] == 1:
			a[i] = 0
		else:
			a[i] = 1
	a.reverse()
	return a
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, list(input())))
	b = list(map(int, list(input())))
	i = 0
	j = n - 1
	ans = []
	while j >= 0:
		if a[i] != b[j]:
			ans.append(j - i + 1)
		else:
			ans.append(1)
			ans.append(j - i + 1)
		a = flip(a)
		a.pop()
		j -= 1
	ans.insert(0, len(ans))
	print(*ans)


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = input().strip()
	b = input().strip()
	bi = n - 1
	f = 0
	(l, r) = (0, n - 1)
	ans = []
	while l != r:
		if f == 0 and a[l] == b[bi] or (f != 0 and a[l] != b[bi]):
			ans.append(1)
		ans.append(abs(l - r) + 1)
		if l < r:
			l += 1
		else:
			l -= 1
		(l, r) = (r, l)
		f ^= 1
		bi -= 1
	if f == 0 and a[l] != b[0] or (f and a[l] == b[0]):
		ans.append(1)
	print(len(ans), end=' ')
	print(*ans)


import sys
t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	var = 0
	ans = []
	for i in range(n):
		if a[i] == b[i]:
			continue
		ans.append(i + 1)
		ans.append(1)
		ans.append(i + 1)
		var += 3
	print(var, end=' ')
	for i in ans:
		print(i, end=' ')
	print()


import sys
input = sys.stdin.readline

def reverse(L):
	return L[::-1]
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().rstrip()))
	b = list(map(int, input().rstrip()))
	ans = []
	for i in range(n):
		if a[n - i - 1] != b[n - i - 1]:
			if a[0] == b[n - i - 1]:
				ans.append(1)
				a[0] ^= 1
			for j in range(n - i):
				a[j] ^= 1
			a[:n - i] = reverse(a[:n - i])
			ans.append(n - i)
	print(len(ans), *ans)


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


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 _ in range(t):
	n = int(input())
	a = input()
	b = input()
	ans = []
	for i in range(n):
		if a[i] != b[i]:
			ans += [i + 1, 1, i + 1]
	print(len(ans), *ans)


for _ in range(int(input())):
	n = int(input())
	l1 = input()
	l2 = input()
	l1 = list(l1)
	l2 = list(l2)
	c = 0
	ans = list()
	for i in range(n):
		if i == 0:
			if l1[i] != l2[i]:
				c += 1
				ans.append(1)
		elif l1[i] != l2[i]:
			c += 3
			ans.extend([i + 1, 1, i + 1])
	print(c, end=' ')
	for i in ans:
		print(i, end=' ')
	print()


for _ in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	d = []
	for i in range(n):
		if a[i] != b[i]:
			d.append(i + 1)
			d.append(1)
			d.append(i + 1)
	d.insert(0, len(d))
	print(*d, sep=' ')


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 bin_not(a):
	NOT = ''
	for i in a:
		NOT += str((int(i) + 1) % 2)
	return NOT
for _ in range(int(input())):
	n = int(input())
	a = input()[::-1]
	b = input()[::-1]
	k = 0
	s = []
	for i in range(n):
		if a[i] == b[i]:
			continue
		if b[i] == a[-1]:
			k += 1
			s += ['1']
		k += 1
		s += [str(n - i)]
		a = a[:i] + bin_not(a[i:])[::-1]
	print(k, ' '.join(s))


I = lambda : list(map(int, input().split()))
import sys
for tc in range(int(input())):
	(n,) = I()
	s = list(input())
	t = list(input())
	ans = []
	for i in range(n - 1, -1, -1):
		if s[i] != t[i]:
			if s[0] != s[i]:
				if s[0] != s[i]:
					s[0] = s[i]
					ans.append(1)
			for j in range(i + 1):
				s[j] = '1' if s[j] == '0' else '0'
			ans.append(i + 1)
			if i == n - 1:
				s = s[::-1]
			else:
				temp = s[:i + 1]
				temp = temp[::-1]
				s = temp + s[i + 1:]
	print(len(ans), *ans)


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


z = input
num = int(z())
for _ in range(num):
	n = int(z())
	l1 = list(z()) + ['0']
	l2 = list(z()) + ['0']
	(lp, lx) = ([], [])
	for i in range(1, n + 1):
		if l1[i] != l1[i - 1]:
			lp.append(i)
		if l2[i] != l2[i - 1]:
			lx.append(i)
	print(len(lp) + len(lx), *lp, *lx[::-1])


import sys
import math
from collections import defaultdict, Counter
t = int(input())
for i in range(t):
	n = int(input())
	a = list(input())
	b = list(input())
	start = a[0]
	curr = a[n - 1]
	c = 0
	l = []
	for j in range(n - 1, 0, -1):
		if a[j] != b[j]:
			a1 = []
			if a[0] == b[j]:
				l += [1, j + 1]
				a[0] = str(int(a[0]) ^ 1)
			else:
				l += [j + 1]
			for k in range(j, -1, -1):
				a1.append(str(int(a[k]) ^ 1))
			a1 += a[j + 1:]
			a = a1[:]
	if a[0] != b[0]:
		a[0] = str(int(a[0]) ^ 1)
		l.append(1)
	print(len(l), *l)


for _ in range(int(input())):
	n = int(input())
	lis = []
	l1 = input()
	l2 = input()
	(a1, b1) = ([], [])
	for i in range(0, n, 1):
		a1.append(int(l1[i]))
		b1.append(int(l2[i]))
	for i in range(n - 1, -1, -1):
		if a1[i] == b1[i]:
			pass
		elif a1[0] == b1[i]:
			lis.append(1)
			if a1[0] == 1:
				a1[0] = 0
			else:
				a1[0] = 1
			lis.append(i + 1)
			for k in range(0, i + 1, 1):
				if a1[k] == 0:
					a1[k] = 1
				else:
					a1[k] = 0
			for j in range(0, i // 2 + 1, 1):
				(a1[j], a1[i - j]) = (a1[i - j], a1[j])
		else:
			lis.append(i + 1)
			for k in range(0, i + 1, 1):
				if a1[k] == 0:
					a1[k] = 1
				else:
					a1[k] = 0
			for j in range(0, i // 2 + 1, 1):
				(a1[j], a1[i - j]) = (a1[i - j], a1[j])
	print(len(lis), end=' ')
	print(*lis)


cases = int(input())
for t in range(cases):
	n = int(input())
	a = input()
	b = input()
	s = 0
	out = []
	for i in range(n - 1, -1, -1):
		if a[i] != b[i]:
			if a[0] == b[i]:
				out.append(1)
				s += 1
				trf = int(a[0], 2) ^ 1
				a = str(trf) + a[1:]
			s += 1
			trf = int(a[:i + 1], 2) ^ int('1' * (i + 1), 2)
			v = bin(trf)[2:]
			lv = len(v)
			str1 = '0' * (i + 1 - lv) + v
			a = str1[::-1] + a[i + 1:]
			out.append(i + 1)
	print(s, *out)


str1 = 'First'
str2 = 'Second'

def rev(c, cnt):
	if cnt % 2 == 0:
		return c
	if c == '0':
		c = '1'
	else:
		c = '0'
	return c

def solve():
	n = int(input())
	a = input()
	b = input()
	ans = list()
	(l, r) = (0, n - 1)
	for i in range(n):
		if i % 2 == 0:
			if rev(a[l], i) == b[n - i - 1]:
				ans.append(1)
			l += 1
		else:
			if rev(a[r], i) == b[n - i - 1]:
				ans.append(1)
			r -= 1
		ans.append(n - i)
	print(len(ans), sep=' ', end=' ')
	for num in ans:
		print(num, sep=' ', end=' ')
	print()

def main():
	t = int(input())
	for i in range(t):
		solve()
main()


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


t = int(input())
while t:
	n = int(input())
	s1 = input()
	s2 = input()
	ans = ''
	check = 0
	b = 0
	f = 0
	count = 0
	for i in range(n - 1, -1, -1):
		if check == 0:
			if s2[i] == s1[n - 1 - b]:
				b = b + 1
			elif s2[i] != s1[0 + f]:
				check = 1
				f = f + 1
				ans = ans + ' ' + str(i + 1)
				count = count + 1
			else:
				check = 1
				f = f + 1
				ans = ans + ' 1 ' + str(i + 1)
				count = count + 2
		elif s2[i] != s1[0 + f]:
			f = f + 1
		elif s2[i] == s1[n - 1 - b]:
			check = 0
			b = b + 1
			ans = ans + ' ' + str(i + 1)
			count = count + 1
		else:
			check = 0
			b = b + 1
			ans = ans + ' 1 ' + str(i + 1)
			count = count + 2
	ans = str(count) + ans
	print(ans)
	t = t - 1


a = int(input())
for i in range(a):
	s = int(input())
	a1 = input()
	a2 = input()
	ans1 = []
	ans2 = []
	for i in range(len(a1)):
		ans1.append(int(a1[i]))
	for i in range(len(a2)):
		ans2.append(int(a2[i]))
	fin = []
	for i in range(len(a2) - 1, -1, -1):
		if ans2[i] == ans1[i]:
			continue
		elif ans1[0] != ans2[i]:
			fin.append(i + 1)
			temp = []
			for j in range(i, -1, -1):
				temp.append(1 - ans1[j])
			for j in range(i + 1):
				ans1[j] = temp[j]
		else:
			fin.append(1)
			ans1[0] = 1 - ans1[0]
			fin.append(i + 1)
			temp = []
			for j in range(i, -1, -1):
				temp.append(1 - ans1[j])
			for j in range(i + 1):
				ans1[j] = temp[j]
	print(len(fin), end=' ')
	print(*fin)


import sys

def rs():
	return sys.stdin.readline().rstrip()

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

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

def ws(s):
	sys.stdout.write(s)
	sys.stdout.write('\n')

def wi(n):
	sys.stdout.write(str(n))
	sys.stdout.write('\n')

def wia(a, sep=' '):
	sys.stdout.write(sep.join([str(x) for x in a]))
	sys.stdout.write('\n')

def solve(n, a, b):
	res = []
	for i in range(n - 1, -1, -1):
		if a[i] == b[i]:
			continue
		if a[0] == b[i]:
			a[0] = 1 - a[0]
			res.append(1)
		if i % 2 == 0:
			a[i // 2] = 1 - a[i // 2]
		for j in range((i + 1) // 2):
			(a[j], a[i - j]) = (1 - a[i - j], 1 - a[j])
		res.append(i + 1)
	return [len(res)] + res

def main():
	for _ in range(ri()):
		n = ri()
		a = [int(si) for si in rs()]
		b = [int(si) for si in rs()]
		wia(solve(n, a, b))
main()


cases = int(input())
for i in range(cases):
	length = int(input())
	a = input()
	b = input()
	prefix = []
	if a == b:
		print(0)
	else:
		a = list(a)
		b = list(b)
		for (index, ele) in enumerate(a):
			if b[index] != ele:
				prefix.append(index + 1)
				prefix.append(1)
				prefix.append(index + 1)
		print(len(prefix), end=' ')
		for p in prefix:
			print(p, end=' ')
		print('\n')


for _ in range(int(input())):
	n = int(input())
	a = input()[:n]
	b = input()[:n]
	m = list(a)
	ans = []
	for x in range(len(a) - 1, 0, -1):
		if m[0] != b[x]:
			ans.append(len(m))
			for i in range(len(m)):
				if m[i] == '1':
					m[i] = '0'
				else:
					m[i] = '1'
			m.reverse()
			m.pop()
		else:
			if m[0] == '0':
				m[0] = '1'
			else:
				m[0] = '0'
			ans.append(1)
			ans.append(len(m))
			for i in range(len(m)):
				if m[i] == '1':
					m[i] = '0'
				else:
					m[i] = '1'
			m.reverse()
			m.pop()
	if m[0] != b[0]:
		ans.append(1)
	print(len(ans), *ans)


t = int(input())
for _ in range(t):
	(n, a, b) = (int(input()), input(), input())
	ans = []
	for i in range(n):
		if a[i] != b[i]:
			ans.append(f'{i + 1}')
			ans.append('1')
			ans.append(f'{i + 1}')
	print(f'{len(ans)}' + ' ' + ' '.join(ans))


def main():
	t = int(input())
	for i in range(t):
		n = int(input())
		str1 = input()
		str2 = input()
		anslist = []
		if str1 == str2:
			print(0)
		else:
			for j in range(n):
				if str1[0] == str2[-j - 1]:
					anslist.append(1)
				anslist.append(n - j)
				tmpstr = ''
				for k in range(0, n - j):
					if str1[k] == '0':
						tmpstr += '1'
					else:
						tmpstr += '0'
				if len(tmpstr) > 1:
					tmpstr = str2[-j - 1] + tmpstr[1:]
				else:
					tmpstr = str2[-1]
				str1 = tmpstr[::-1] + str1[n - j:]
			print(len(anslist), end=' ')
			for j in range(len(anslist) - 1):
				print(anslist[j], end=' ')
			print(anslist[len(anslist) - 1])
main()


import copy
t = int(input())
while t:
	t -= 1
	n = int(input())
	a = list(input())
	b = list(input())
	flip = []
	k = 0
	for i in range(n):
		if n - i - 1 == 0:
			if a[0] != b[0]:
				flip.append(1)
				k += 1
		elif a[n - i - 1] != b[n - i - 1]:
			flip.append(n - i)
			flip.append(1)
			flip.append(n - i)
			k += 3
	print(k, end=' ')
	print(*flip)


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

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

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

def solve():
	n = int(input())
	aa = list(input())
	bb = list(input())
	res = []
	for i in range(n - 1, 0, -1):
		if aa[i] != bb[i]:
			if aa[0] == aa[i]:
				res += [i + 1]
			else:
				res += [1, i + 1]
				aa[0] = '0' if aa[0] == '1' else '1'
			an = []
			for j in range(i, -1, -1):
				an.append('1' if aa[j] == '0' else '0')
			aa[:i + 1] = an
	if aa[0] != bb[0]:
		res.append(1)
		aa[0] = '0' if aa[0] == '1' else '1'
	print(len(res), ' '.join(map(str, res)))

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


g = int(input())
for _ in range(g):
	n = int(input())
	A = input()
	B = input()
	count = 0
	C = []
	for i in range(n - 1, -1, -1):
		if B[i] != A[i]:
			if B[i] != A[0]:
				C.append(i + 1)
				mystr = ''
				for j in range(0, i + 1):
					if A[j] == '0':
						mystr = str(1) + mystr
					else:
						mystr = str(0) + mystr
				A = mystr + A[i + 1:]
				count += 1
			else:
				C.append(1)
				A = str(1 - int(A[0])) + A[1:]
				C.append(i + 1)
				E = list(A[:i + 1])
				mystr = ''
				for j in range(0, i + 1):
					if A[j] == '0':
						mystr = str(1) + mystr
					else:
						mystr = str(0) + mystr
				A = mystr + A[i + 1:]
				count += 2
	if count == 0:
		print(count)
	else:
		print(count, end=' ')
		for i in range(0, count):
			if i == count - 1:
				print(C[i])
			else:
				print(C[i], end=' ')


def prf(a, b):
	ans = []
	for i in range(len(a)):
		if a[i] != b[i]:
			if i > 0:
				ans.append(i + 1)
			ans.append(1)
			if i > 0:
				ans.append(i + 1)
	print(len(ans), *ans)
	return ''
for i in range(int(input())):
	n = input()
	a = input()
	b = input()
	print(prf(a, b))


def solve(ls1, ls2, debug=0):
	n = len(ls1)
	result = []
	for i in range(n):
		if i % 2:
			j = -1 - i // 2
			x = ls1[j] ^ 1
		else:
			j = i // 2
			x = ls1[j]
		y = ls2[-i - 1]
		if debug:
			print(f'i: {i}, j: {j}, x: {x}, y: {y}')
		if x == y:
			result.append(1)
		result.append(n - i)
	return result

def main(istr, ostr):
	t = int(istr.readline())
	for _ in range(t):
		n = int(istr.readline())
		ls1 = list(map(int, istr.readline().strip()))
		ls2 = list(map(int, istr.readline().strip()))
		result = solve(ls1, ls2)
		print(len(result), *result, file=ostr)
import sys
main(sys.stdin, sys.stdout)


I = input
exec(int(I()) * "I();a=[f'{i} 1 {i}'for i,(x,y)in enumerate(zip(I(),I()),1)if x!=y];print(len(a)*3,*a);")


import os
from sys import stdin, stdout

def solve(tc):
	n = int(stdin.readline().strip())
	seq = list(map(int, stdin.readline().strip()))
	obj = list(map(int, stdin.readline().strip()))
	hi = n - 1
	while hi >= 0 and seq[hi] == obj[hi]:
		hi -= 1
	ans = []
	while hi >= 0:
		if seq[hi] != obj[hi]:
			if hi > 0 and seq[0] == obj[hi]:
				ans.append(1)
				seq[0] ^= 1
			ans.append(hi + 1)
			for i in range(hi + 1):
				seq[i] ^= 1
			l = 0
			r = hi
			while l < r:
				(seq[l], seq[r]) = (seq[r], seq[l])
				l += 1
				r -= 1
		hi -= 1
	print(len(ans), *ans)
tcs = 1
tcs = int(stdin.readline().strip())
tc = 1
while tc <= tcs:
	solve(tc)
	tc += 1


t = int(input())
while t > 0:
	n = int(input())
	a = list(str(input()))
	b = list(str(input()))
	a = list(map(int, a))
	b = list(map(int, b))
	level = []
	aclone = []
	for i in range(n):
		if a[i] == 0:
			aclone.append(1)
		else:
			aclone.append(0)
	for i in range(n - 1, -1, -1):
		if a[i] != b[i]:
			if i != 0:
				if a[0] != b[i]:
					level.append(i + 1)
					d = list(a)
					a = aclone[::-1]
					aclone = d[::-1]
				else:
					level.append(1)
					if a[0] == 1:
						a[0] = 0
						aclone[0] = 1
					else:
						a[0] = 1
						aclone[0] = 0
					level.append(i + 1)
					d = list(a)
					a = aclone[::-1]
					aclone = d[::-1]
			else:
				level.append(1)
		a.pop()
		aclone.pop()
	print(len(level), ' '.join(map(str, level)))
	t = t - 1


from sys import stdin, stdout
import math

def solve():
	n = int(input())
	a = input()
	b = input()
	(ans, ans2) = ([], [])
	a += '0'
	b += '0'
	for i in range(1, n + 1):
		if a[i] != a[i - 1]:
			ans.append(i)
		if b[i] != b[i - 1]:
			ans2.append(i)
	ans.extend(ans2[::-1])
	print(len(ans), end=' ')
	for i in ans:
		print(i, end=' ')
	print()
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop, heapify
import math
from collections import *
from functools import reduce, cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip('\n').split()]

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

def val():
	return int(input().rstrip('\n'))

def li2():
	return [i for i in input().rstrip('\n')]

def li3():
	return [int(i) for i in input().rstrip('\n')]

def do(l):
	l1 = []
	for i in range(len(l) - 1, -1, -1):
		l1.append(1 - l[i])
	return l1[:]
for _ in range(val()):
	n = val()
	a = li3()
	b = li3()
	ans = []
	for i in range(n - 1, -1, -1):
		if a[0] != b[i]:
			ans.append(i + 1)
			a = do(a[:i + 1]) + a[i + 1:]
		else:
			ans.append(1)
			a[0] = 1 - a[0]
			ans.append(i + 1)
			a = do(a[:i + 1]) + a[i + 1:]
	print(len(ans), *ans)


for _ in range(int(input())):
	n = int(input())
	a = list(str(input()))
	b = list(str(input()))
	res = []
	for i in range(n):
		if a[i] != b[i]:
			res += [i + 1, 1, i + 1]
	print(len(res), *res)


import sys, collections

def flip(num):
	for i in range(num):
		if a[i] == '0':
			a[i] = '1'
		else:
			a[i] = '0'
	a[:num].reverse()
tc = int(sys.stdin.readline())
for _ in range(tc):
	n = int(sys.stdin.readline())
	a = list(sys.stdin.readline().rstrip())
	b = list(sys.stdin.readline().rstrip())
	temp = []
	for i in range(n):
		if a[i] != b[i]:
			if i > 0:
				temp.append(i + 1)
			temp.append(1)
			if i > 0:
				temp.append(i + 1)
	print(len(temp), end=' ')
	print(' '.join(map(str, temp)))


for _ in range(int(input())):
	n = int(input())
	g = input()
	d = input()
	if g == d:
		print(0)
	else:
		c = 0
		g = list(g)
		d = list(d)
		pl = []
		for i in range(n):
			if g[0] == d[n - i - 1]:
				c += 1
				pl.append(1)
			pl.append(n - i)
			c += 1
			del g[0]
			for j in range(n - i - 1):
				if g[j] == '0':
					g[j] = '1'
				else:
					g[j] = '0'
			g = g[::-1]
		print(c, end=' ')
		for i in pl:
			print(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)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from collections import Counter as cc
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	ans = []
	cnt = 0
	for i in range(n - 1, -1, -1):
		if s1[i] == s2[i]:
			continue
		else:
			if s2[i] == s1[0]:
				ans.append(1)
				s1[0] = str(1 ^ int(s1[0]))
			for j in range(i + 1):
				s1[j] = str(1 ^ int(s1[j]))
			ans.append(i + 1)
			s1 = s1[:i + 1][::-1] + s1[i + 1:]
	print(len(ans), *ans)


def swap(ind):
	global a
	for i in range(ind + 1):
		a[i] = 1 - a[i]
	for i in range(ind // 2 + 1):
		(a[i], a[ind - i]) = (a[ind - i], a[i])
for _ in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	a = [int(i) for i in a]
	b = [int(i) for i in b]
	ans = []
	for i in range(n - 1, -1, -1):
		if a[i] == b[i]:
			continue
		if a[i] == a[0]:
			swap(i)
			ans.append(i + 1)
		else:
			swap(0)
			swap(i)
			ans.append(1)
			ans.append(i + 1)
	print(len(ans), ' ')
	print(*ans)


import sys

def flip(a):
	return [not i for i in reversed(a)]

def prefix_flip(a, b):
	operations = []
	while True:
		if not a:
			return operations
		elif a[-1] == b[-1]:
			del a[-1]
			del b[-1]
		elif a[0] != b[-1]:
			operations.append(len(a))
			a = flip(a)
		else:
			operations.append(1)
			a[0] = not a[0]

def read_bitstring(fd):
	return [i == '1' for i in next(fd).rstrip()]

def test(fd):
	next(fd)
	a = read_bitstring(fd)
	b = read_bitstring(fd)
	operations = prefix_flip(a, b)
	print(len(operations), end=' ')
	print(*operations)

def main(fd=sys.stdin):
	t = int(next(fd))
	for _ in range(t):
		test(fd)
main()


def transform(a, pre):
	b = a.copy()
	for i in range(pre):
		b[i] = 1 - a[pre - 1 - i]
	return b
for i in range(int(input())):
	n = int(input())
	a = list(map(int, list(input())))
	b = list(map(int, list(input())))
	ans = []
	lid = n - 1
	while lid > -1:
		if a[lid] == b[lid]:
			lid -= 1
		elif a[0] == b[lid]:
			a = transform(a, 1)
			ans.append(1)
		else:
			a = transform(a, lid + 1)
			ans.append(lid + 1)
	print(len(ans), ' '.join(map(str, ans)))


def fu(a, x):
	for i in range(x):
		a[i] = str((int(a[i]) + 1) % 2)
	a[:x] = a[:x][::-1]
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(input())
	b = list(input())
	c = []
	for i in range(n):
		if a[n - i - 1] != b[n - i - 1]:
			if a[0] == b[n - i - 1]:
				c.append(n - i)
				fu(a, n - i)
				c.append(1)
				fu(a, 1)
				c.append(n - i)
				fu(a, n - i)
			else:
				c.append(n - i)
				fu(a, n - i)
	print(len(c), *c)


t = int(input())
for i in range(t):
	n = int(input())
	ch1 = input()
	ch2 = input()
	L = []
	nb = 0
	s = ''
	for i in range(1, n):
		if ch1[i] != ch1[i - 1]:
			s += str(i)
			s += ' '
			nb += 1
	if ch1[n - 1] != ch2[n - 1]:
		s += str(n)
		s += ' '
		nb += 1
	for i in range(n - 2, -1, -1):
		if ch2[i] != ch2[i + 1]:
			s += str(i + 1)
			s += ' '
			nb += 1
	if ch1 != ch2:
		print(nb, s)
	else:
		print(0)


T = int(input())

def f(i, c, x, y):
	if c % 2:
		m = a[n - y - i - 1]
	else:
		m = a[x + i]
	if c % 2:
		return not m
	else:
		return m
for test in range(T):
	n = int(input())
	a = [bool(int(u)) for u in input()]
	b = [bool(int(u)) for u in input()]
	ans = []
	c = 0
	x = 0
	y = 0
	for i in range(n):
		if f(n - 1 - i, c, x, y) == b[n - 1 - i]:
			continue
		else:
			if f(0, c, x, y) == b[n - 1 - i]:
				ans.append(1)
			ans.append(n - i)
			c += 1
			if c % 2:
				y = i - x
			else:
				x = i - y
	print(len(ans), *ans)


from collections import deque

def solve(n, a, b):
	ans = deque()
	for i in range(n):
		if a[n - 1 - i] != b[n - 1 - i]:
			if a[0] == b[n - 1 - i]:
				ans.append(1)
				a[0] = 1 - a[0]
				ans.append(n - i)
				st = deque([])
				for j in range(n - i):
					st.append(1 - a[j])
				for j in range(n - i):
					a[n - i - 1 - j] = st.popleft()
			else:
				ans.append(n - i)
				st = deque([])
				for j in range(n - i):
					st.append(1 - a[j])
				for j in range(n - i):
					a[n - i - 1 - j] = st.popleft()
	if len(ans) == 0:
		print(0)
		return
	else:
		print(len(ans), *ans)
		return
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, list(input())))
	b = list(map(int, list(input())))
	solve(n, a, b)


for i in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	res = []
	e = n
	for j in range(n):
		if j % 2 == 0:
			d = a[j // 2]
		else:
			d = a[n - j // 2 - 1]
			d = (d == '1') * '0' + '1' * (d == '0')
		c = b[n - j - 1]
		if c == d:
			res.append(1)
			res.append(e)
		else:
			res.append(e)
		e = e - 1
	print(len(res), *res)


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	l = []
	for i in range(n):
		if s1[i] != s2[i]:
			l.extend([i + 1, 1, i + 1])
	print(len(l), end=' ')
	print(*l)


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)


t = int(input())
while t:
	t -= 1
	n = int(input())
	s2 = list(input())
	s1 = list(input())
	ans = []
	for i in range(n - 1, -1, -1):
		if s1[i] != s2[i]:
			if s1[i] == s2[0]:
				s2[0] = '0' if s2[0] == '1' else '1'
				ans.append(1)
			for j in range(i, i // 2, -1):
				(s2[j], s2[i - j]) = (s2[i - j], s2[j])
			for j in range(i, -1, -1):
				s2[j] = '0' if s2[j] == '1' else '1'
			ans.append(i + 1)
	if s2[0] != s1[0]:
		s2[0] = '0' if s2[0] == '1' else '1'
		ans.append(1)
	print(len(ans), *ans)


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	k = 0
	ans = []
	if a == b:
		print(k)
	else:
		for i in range(n - 1):
			c = ''
			if a[n - i - 1] == b[n - i - 1]:
				continue
			elif a[0] != b[n - i - 1]:
				ans.append(n - i)
				for j in range(n - i):
					if a[j] == '0':
						c += '1'
					else:
						c += '0'
				c = c[::-1]
				a = c + a[n - i:]
				k += 1
			else:
				if a[0] == '0':
					a = '1' + a[1:]
				else:
					a = '0' + a[1:]
				ans.append(1)
				ans.append(n - i)
				for j in range(n - i):
					if a[j] == '0':
						c += '1'
					else:
						c += '0'
				c = c[::-1]
				a = c + a[n - i:]
				k += 2
		if a[0] != b[0]:
			k += 1
			ans.append(1)
		print(k, *ans)


from __future__ import division, print_function
MOD = 998244353
mod = 10 ** 9 + 7

def prepare_factorial():
	fact = [1]
	for i in range(1, 100005):
		fact.append(fact[-1] * i % mod)
	ifact = [0] * 100005
	ifact[100004] = pow(fact[100004], mod - 2, mod)
	for i in range(100004, 0, -1):
		ifact[i - 1] = i * ifact[i] % mod
	return (fact, ifact)
import sys
from bisect import bisect_left, bisect_right, insort
from math import floor, ceil, sqrt, degrees, atan, pi, log, sin, radians
from heapq import heappop, heapify, heappush
from collections import Counter, defaultdict, deque

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

def ncr(n, r, fact, ifact):
	t = fact[n] * (ifact[r] * ifact[n - r]) % mod % mod
	return t

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

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

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

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

def lcm(x, y):
	return x * y // GCD(x, y)

def get_xor(n):
	return [n, 1, n + 1, 0][n % 4]

def fast_expo(a, b):
	res = 1
	while b:
		if b & 1:
			res = res * a
			res %= MOD
			b -= 1
		else:
			a = a * a
			a %= MOD
			b >>= 1
	res %= MOD
	return res

def get_n(P):
	ans = (-1 + sqrt(1 + 8 * P)) // 2
	return ans

def reverse(a, r):
	l = 0
	if r & 1 == 0:
		if a[r // 2] == '0':
			a[r // 2] = '1'
		else:
			a[r // 2] = '0'
	while l < r:
		(a[l], a[r]) = (a[r], a[l])
		if a[l] == '0':
			a[l] = '1'
		elif a[l] == '1':
			a[l] = '0'
		if a[r] == '0':
			a[r] = '1'
		elif a[r] == '1':
			a[r] = '0'
		l += 1
		r -= 1
	return a

def solve():
	n = int(input())
	a = list(input())
	b = list(input())
	out = []
	for i in range(n - 1, -1, -1):
		if b[i] == a[i]:
			continue
		elif b[i] != a[0]:
			out.append(i + 1)
			a = reverse(a, i)
		else:
			out.append(1)
			if a[0] == '1':
				a[0] = '0'
			else:
				a[0] = '1'
			out.append(i + 1)
			a = reverse(a, i)
	print(len(out), *out)
	return

def main():
	T = int(input())
	while T:
		solve()
		T -= 1
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')
main()


import sys
import math, bisect
from collections import defaultdict
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, OrderedDict

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

def Neo():
	return list(map(int, input().split()))
for _ in range(int(input())):
	N = int(input())
	a = input()
	b = input()
	A = list(a)
	B = list(b)
	Ans = []
	for i in range(N):
		A[i] = int(A[i])
		B[i] = int(B[i])
	for i in B[::-1]:
		if i == A[0]:
			Ans.append(1)
		Ans.append(len(A))
		for j in range(len(A)):
			if A[j] == 0:
				A[j] = 1
			else:
				A[j] = 0
		A = A[::-1]
		A = A[:-1]
	print(len(Ans))
	print(*Ans)


import sys
input = sys.stdin.readline
t = int(input())
for tt in range(t):
	n = int(input())
	a1 = input().strip('\n')
	b1 = input().strip('\n')
	ans = []
	a = []
	b = []
	for i in a1:
		a.append(int(i))
	for i in b1:
		b.append(int(i))
	for i in range(n - 1, -1, -1):
		if a[0] == b[i]:
			a[0] ^= 1
			ans.append(1)
		ans.append(i + 1)
		temp = a[0:i + 1]
		temp = temp[::-1]
		length = len(temp)
		for j in range(length):
			temp[j] ^= 1
		for j in range(i + 1):
			a[j] = temp[j]
	print(len(ans), end=' ')
	for i in ans:
		print(i, end=' ')
	print()


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	c = 0
	v = []
	for i in range(n):
		if a[i] != b[i]:
			c += 3
			v.append(str(i + 1))
			v.append('1')
			v.append(str(i + 1))
	v = [str(c)] + v
	print(' '.join(v))


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	a += '0'
	b += '0'
	(l1, l2) = ([], [])
	for i in range(1, n + 1):
		if a[i] != a[i - 1]:
			l1.append(i)
		if b[i] != b[i - 1]:
			l2.append(i)
	l2.reverse()
	l3 = l1 + l2
	print(len(l3), sep=' ', end=' ')
	for i in l3:
		print(i, sep=' ', end=' ')
	print(sep='')


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)


def doOp(a, i):
	s = ''
	s = [not x for x in a[:i]]
	s.reverse()
	return s + a[i:]
for _ in range(int(input())):
	n = int(input())
	a = [True if x == '1' else False for x in input()]
	b = [True if x == '1' else False for x in input()]
	rb = n - 1
	ct = 0
	ans = []
	while rb >= 0:
		if a[rb] != b[rb]:
			if a[0] == b[rb]:
				ct += 1
				ans.append(1)
				a[0] = ~a[0]
			ct += 1
			ans.append(rb + 1)
			a = doOp(a, rb + 1)
		rb -= 1
	if len(ans) == 0:
		print(0)
	else:
		for i in range(len(ans)):
			if i == 0:
				print(ct, end=' ')
			else:
				print(ans[i - 1], end=' ')
		print(ans[-1])


import math
from collections import *
import sys
from functools import reduce
import time
from itertools import groupby

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

def get_ints():
	return map(int, input().strip().split())

def get_list():
	return list(get_ints())

def get_string():
	return list(input().strip().split())

def printxsp(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')
DIRECTIONS = [(+0, +1), (+0, -1), (+1, +0), (+1, -1)]
NEIGHBOURS = [(-1, -1), (-1, +0), (-1, +1), (+0, -1), (+1, +1), (+1, +0), (+1, -1), (+0, +1)]
CAPS_ALPHABETS = {chr(i + ord('A')): i for i in range(26)}
SMOL_ALPHABETS = {chr(i + ord('a')): i for i in range(26)}
INF = float('inf')
S34t = time.time()
for _testcases_ in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	j = n - 1
	moves = 0
	ans = []
	while j >= 0:
		if a[j] != b[j]:
			if a[0] == b[j]:
				moves += 1
				if a[0] == '1':
					a[0] = '0'
				else:
					a[0] = '1'
				ans.append(1)
			for i in range((j + 2) // 2):
				if i == j - i:
					if a[i] == '1':
						a[i] = '0'
					else:
						a[i] = '1'
				else:
					(a[i], a[j - i]) = (a[j - i], a[i])
					if a[i] == '0':
						a[i] = '1'
					else:
						a[i] = '0'
					if a[j - i] == '0':
						a[j - i] = '1'
					else:
						a[j - i] = '0'
			moves += 1
			ans.append(j + 1)
		j -= 1
	print(moves, *ans)
S34p = time.time()


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		n = int(input())
		a = list(input())
		b = list(input())
		ans = []
		for i in range(n - 1, -1, -1):
			if a[i] != b[i]:
				if i == 0:
					ans.append(1)
					continue
				ans.append(i + 1)
				ans.append(1)
				ans.append(i + 1)
		if len(ans) == 0:
			print(0)
		else:
			print(len(ans), end=' ')
			for i in ans:
				print(i, 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 = self.buffer.write if self.writable else None

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

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

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

class IOWrapper(IOBase):

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


def flip(s, k):
	pre = ''.join(reversed(['1' if _ == '0' else '0' for _ in s[:k]]))
	pos = s[k:]
	return pre + pos
for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	ret = []
	for i in reversed(list(range(n))):
		while a[i] != b[i]:
			if a[0] == b[i]:
				p = 1
			else:
				p = i + 1
			ret.append(p)
			a = flip(a, p)
	print(len(ret), *ret)


def op(st, l):
	ans = ''
	for i in range(l):
		if st[i] == '1':
			ans += '0'
		else:
			ans += '1'
	ans = ans[::-1] + st[l:]
	return ans
for i in range(int(input())):
	n = int(input())
	b = input()
	a = input()
	count = 0
	ans = []
	for i in range(n):
		if a[i] == b[n - i - 1]:
			if b[0] == a[i]:
				ans.append(n - i)
				b = op(b, n - i)
			else:
				ans.append(1)
				b = op(b, 1)
				ans.append(n - i)
				b = op(b, n - i)
	if a != b:
		ans.append(n)
	print(len(ans), *ans)


def find(s1, s2):
	if len(s1) == 1:
		if s1 == s2:
			return []
		else:
			return [1]
	indices = [-1] * len(s1)
	cur = len(s1) - 1
	val = 0
	for i in range(len(s1)):
		indices[cur] = val
		cur -= 2
		val += 1
		if cur < 0:
			break
	if indices[0] == -1:
		cur = 0
		for i in range(len(s1)):
			indices[cur] = val
			val += 1
			cur += 2
			if cur > len(s1) - 1:
				break
	else:
		cur = 1
		for i in range(len(s1)):
			indices[cur] = val
			val += 1
			cur += 2
			if cur > len(s1) - 1:
				break
	ans = []
	temp = 1
	for i in range(len(s1) - 1, -1, -1):
		if (int(s1[indices[i]]) + temp) % 2 == int(s2[i]) % 2:
			ans += [i + 1]
		else:
			ans += [1, i + 1]
		temp += 1
	return ans
ANS = []
for _ in range(int(input())):
	input()
	s1 = input()
	s2 = input()
	ans = find(s1, s2)
	ans = [str(x) for x in ans]
	ans = [str(len(ans))] + ans
	ANS += [' '.join(ans)]
print('\n'.join(ANS))


cases = int(input())
for t in range(cases):
	n = int(input())
	a = list(map(int, list(input())))
	b = list(map(int, list(input())))
	c = 0
	s = []
	for i in range(n):
		if a[n - 1 - i] != b[n - 1 - i]:
			if a[0] == b[n - 1 - i]:
				c += 1
				a[0] ^= 1
				s.append(1)
			c += 1
			s.append(n - i)
			a = [j ^ 1 for j in a[:n - i]][::-1]
	if c == 0:
		print(c)
	else:
		print(c, *s)


to_bool = lambda c: c == '1'

def operation_iter(l, e):
	while e >= 0:
		yield (not l[e])
		e -= 1

def operation_edit(l, e):
	l[:e + 1] = list(operation_iter(l, e))

def solve():
	n = int(input())
	a = list(map(to_bool, input()))
	b = list(map(to_bool, input()))
	history = []
	key = a[-1]
	for i in range(n - 2, -1, -1):
		if a[i] != key:
			if a[0] == key:
				z = i
				while z >= 0 and a[z] != key:
					z -= 1
				history.append(z + 1)
				operation_edit(a, z)
			history.append(i + 1)
			operation_edit(a, i)
	for i in range(n - 1, -1, -1):
		if a[i] != b[i]:
			history.append(i + 1)
			operation_edit(a, i)
		i -= 1
	print(len(history), *history)
for _ in range(int(input())):
	solve()


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
MOD = 998244353
T = int(stdin.readline())
for _ in range(T):
	n = int(stdin.readline())
	a = stdin.readline().strip('\n')
	b = stdin.readline().strip('\n')
	fin = []
	for i in range(n):
		if a[i] == b[i]:
			continue
		if i == 0:
			fin.append(1)
			continue
		fin.append(i + 1)
		fin.append(1)
		fin.append(i + 1)
	h = len(fin)
	print(h, end=' ')
	for i in range(h):
		print(fin[i], end=' ')
	print('')


def solve(n, a, b):
	cmds = []
	for i in range(n):
		if a[i] != b[i]:
			cmds.extend([i + 1, 1, i + 1])
	return cmds
t = int(input())
for case in range(t):
	x = solve(int(input()), input(), input())
	print(len(x), *x)


for _ in range(int(input())):
	n = int(input())
	a = str(input())
	b = str(input())
	ans = []
	i = n - 1
	while i >= 0:
		if int(a[i]) != int(b[i]):
			if int(a[0]) != int(b[i]):
				ans.append(i + 1)
			else:
				ans.append(1)
				a = b[i] + a[1:]
				ans.append(i + 1)
			for j in range(i + 1):
				if a[j] == '1':
					a = a[:j] + '0' + a[j + 1:]
				else:
					a = a[:j] + '1' + a[j + 1:]
			a = a[:i + 1][::-1] + a[i + 1:]
		i = i - 1
	print(len(ans), *ans, sep=' ')


import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
	return int(input())

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

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

def change(a, n):
	temp = []
	for i in range(n):
		temp.append(1 - a[i])
	return temp[::-1] + a[n:]
for _ in range(r()):
	n = r()
	a = list(map(int, input()))
	b = list(map(int, input()))
	ans = True
	for i in range(n):
		if a[i] != b[i]:
			ans = False
			break
	if ans:
		print(0)
		continue
	res = []
	for i in range(n - 1, -1, -1):
		if b[i] == a[i]:
			continue
		if b[i] == a[0]:
			a[0] = 1 - a[0]
			res.append(1)
			res.append(i + 1)
			a = change(a, i + 1)
		else:
			res.append(i + 1)
			a = change(a, i + 1)
	print(len(res), *res)


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


from __future__ import division, print_function
import sys
from atexit import register
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream
sys.stdin = stream(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = stream()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))

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

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

def flip(a):
	return 0 if a == 1 else 1

def solve():
	n = read_int()
	a = list(map(int, input()))
	b = list(map(int, input()))
	end = n - 1
	operations = []
	while end > -1:
		if a[end] != b[end]:
			if a[0] == a[end]:
				flipped = list(map(flip, a[:end + 1]))
				flipped.reverse()
				a[:end + 1] = flipped
				operations.append(end + 1)
			else:
				a[0] = flip(a[0])
				operations.append(1)
				flipped = list(map(flip, a[:end + 1]))
				flipped.reverse()
				a[:end + 1] = flipped
				operations.append(end + 1)
			a[end] = b[end]
		end -= 1
	print(len(operations), ' '.join(map(str, operations)))
T = read_int()
for _ in range(T):
	solve()


def funny(a, l):
	m = []
	for i in range(a):
		l[i] = 1 - l[i]
		m.append(l[i])
	m.reverse()
	l = m[:] + l[a:]
	return l
t = int(input())
final = []
for i in range(t):
	n = int(input())
	a = [int(x) for x in input()]
	b = [int(x) for x in input()]
	k = []
	juju = []
	while a != b:
		count = 0
		for j in range(len(a)):
			if a[len(a) - j - 1] == b[len(b) - j - 1]:
				count += 1
			else:
				break
		count = len(a) - count
		if a[0] == a[count - 1]:
			p = count
		else:
			p = 1
			for i in range(count - 1):
				if a[0] == a[count - 1 - i]:
					p = count - i
					break
		a = funny(p, a)
		juju.append(p)
	final.append([len(juju), *juju])
for i in range(t):
	print(*final[i])


def comp(val):
	return 1 if val == 0 else 0

def invert(a, p):
	temp = [comp(x) for x in a[0:p]][::-1]
	a[0:p] = temp
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().strip()]
	b = [int(x) for x in input().strip()]
	i = n - 1
	k = 0
	op = []
	while i >= 0:
		if a[i] == b[i]:
			i -= 1
			continue
		else:
			if b[i] == a[0]:
				k += 1
				op.append(1)
				a[0] = 1 if a[0] == 0 else 0
			k += 1
			op.append(i + 1)
			invert(a, i + 1)
			i -= 1
	print(k, end=' ')
	print(' '.join([str(x) for x in op]))


import sys
from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	res = []
	for i in range(n - 1, -1, -1):
		if a[i] == b[i]:
			continue
		if b[i] == '0':
			if a[0] == '0':
				a[0] = '1'
				res.append(1)
			res.append(i + 1)
		else:
			if a[0] == '1':
				a[0] == '0'
				res.append(1)
			res.append(i + 1)
		for j in range(i + 1):
			if a[j] == '1':
				a[j] = '0'
			else:
				a[j] = '1'
		for j in range((i + 1) // 2):
			(a[j], a[i - j]) = (a[i - j], a[j])
	print(len(res), *res)


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


import sys, os.path
from collections import deque
from fractions import Fraction as f

def IO():
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
		print = sys.stdout.write

def nextInt():
	return int(input())

def nextTuple():
	return [int(a) for a in input().split()]

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

def nextLine():
	return input()

def nextStringArray():
	return list(input().split())
IO()
t = nextInt()
for _ in range(t):
	sb = []
	n = nextInt()
	a = list(nextLine())
	b = list(nextLine())
	ptr = n - 1
	for i in range(n):
		if b[ptr] == a[0]:
			sb.append('1')
		if True:
			sb.append(str(ptr + 1))
			for j in range(ptr + 1):
				if a[j] == '0':
					a[j] = '1'
				else:
					a[j] = '0'
		a = a[0:ptr + 1][::-1] + a[ptr + 1:]
		ptr -= 1
	print(len(sb), end=' ')
	print(' '.join(sb), end='')
	print()