This is the hard 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 $2n$ operations. It can be proved that it is always possible.


-----Input-----

The first line contains a single integer $t$ ($1\le t\le 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\le n\le 10^5$)  — 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 $10^5$.


-----Output-----

For each test case, output an integer $k$ ($0\le k\le 2n$), followed by $k$ integers $p_1,\ldots,p_k$ ($1\le p_i\le 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\to 11\to 00\to 10$.

In the second test case, we have $01011\to 00101\to 11101\to 01000\to 10100\to 00100\to 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.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Constructive algorithms

String algorithms

Amortized analysis

Implementation

Data structures


Solutions:
for tc in range(int(input())):
	n = int(input())
	A = input()
	B = input()
	steps = []
	for i in range(n):
		if i % 2 == 0:
			if A[int(i / 2)] != B[n - 1 - i]:
				steps.append(n - i)
			else:
				steps.append(1)
				steps.append(n - i)
		elif A[n - 1 - int(i / 2)] == B[n - 1 - i]:
			steps.append(n - i)
		else:
			steps.append(1)
			steps.append(n - i)
	print(len(steps), end=' ')
	for i in steps:
		print(i, end=' ')
	print()


import sys
r = sys.stdin.readline

def revAndnot(bit, idx):
	tmp = ''
	for i in range(idx):
		tmp += '1' if bit[i] == '0' else '0'
	return tmp[::-1] + bit[idx:]
for _ in range(int(r())):
	n = int(r())
	a = r().strip()
	b = r().strip()
	ans = []
	flip = False
	idx = 0
	for i in range(n - 1, -1, -1):
		if flip ^ (a[idx] == b[i]):
			ans.append(str(1))
		ans.append(str(i + 1))
		if flip:
			idx -= i
		else:
			idx += i
		flip ^= True
	print(len(ans), end=' ')
	print(' '.join(ans))


import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
	n = int(input())
	a = input()
	b = input()
	scheck = []
	pos = 0
	pos1 = n - 1
	reverse = 0
	for j in range(n - 1, -1, -1):
		if not reverse:
			if a[pos] != b[j]:
				scheck.append(j + 1)
			else:
				scheck.append(1)
				scheck.append(j + 1)
			pos += 1
			reverse = 1
		else:
			if a[pos1] != b[j]:
				scheck.append(1)
				scheck.append(j + 1)
			else:
				scheck.append(j + 1)
			pos1 -= 1
			reverse = 0
	print(len(scheck), *scheck)


import os
import sys
from io import BytesIO, IOBase
import math
import itertools
import bisect
import heapq

def main():
	pass
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 binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

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

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] > arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def maxfac(n):
	root = int(n ** 0.5)
	for i in range(2, root + 1):
		if n % i == 0:
			return n // i
	return n

def p2(n):
	c = 0
	while n % 2 == 0:
		n //= 2
		c += 1
	return c

def seive(n):
	primes = [True] * (n + 1)
	primes[1] = primes[0] = False
	for i in range(2, n + 1):
		if primes[i]:
			for j in range(i + i, n + 1, i):
				primes[j] = False
	p = []
	for i in range(0, n + 1):
		if primes[i]:
			p.append(i)
	return p

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

def denofactinverse(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return pow(fac, m - 2, m)

def numofact(n, m):
	fac = 1
	for i in range(1, n + 1):
		fac = fac * i % m
	return fac
for xyz in range(0, int(input())):
	n = int(input())
	a = input() + '1'
	b = input() + '1'
	(cona, conb) = ([], [])
	for i in range(1, n + 1):
		if a[i] != a[i - 1]:
			cona.append(i)
		if b[i] != b[i - 1]:
			conb.append(i)
	cona += conb[::-1]
	print(len(cona), *cona)


from sys import stdin
import math
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
	n = int(inp())
	a = inp()
	b = inp()
	eq = []
	fin = []
	if n == 1:
		if a == b:
			print(0)
		else:
			print('1 1')
	else:
		for i in range(n - 1):
			if a[i] != a[i + 1]:
				eq.append(i + 1)
		for i in range(n - 2, -1, -1):
			if b[i] != b[i + 1]:
				fin.append(i + 1)
		if a[-1] != b[-1]:
			eq.append(n)
		print(len(eq) + len(fin), end=' ')
		print(*eq, end=' ')
		print(*fin)


import sys

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

def input_split():
	return [int(i) for i in input().split()]
testCases = int(input())
answers = []

def update_zero(arr, diff, num_flips):
	if num_flips % 2 == 0:
		i = -diff
		arr[i] = 1 - arr[i]
	else:
		i = diff
		arr[i] = 1 - arr[i]

def fetch_val(arr, index, diff, num_flips):
	if num_flips % 2 == 0:
		i = -diff + index
		ans = arr[i]
	else:
		i = diff - index
		ans = 1 - arr[i]
	return ans

def print_arr(arr, diff, num_flips, ans_till_now):
	temp = [fetch_val(arr, i, diff, num_flips) for i in range(ans_till_now[-1])]
	temp = temp + arr[ans_till_now[-1]:]
	print('array is ')
	print(*temp, sep=' ')
for _ in range(testCases):
	n = int(input())
	arr = [int(i) for i in input()]
	barr = [int(i) for i in input()]
	ans = []
	num_flips = 0
	diff = 0
	for i in range(n):
		index = n - 1 - i
		desired = barr[index]
		if fetch_val(arr, index, diff, num_flips) == desired:
			continue
		else:
			target = fetch_val(arr, 0, diff, num_flips)
			if target == 1 - desired:
				ans.append(index + 1)
				num_flips += 1
				diff = index - diff
			else:
				ans.append(1)
				update_zero(arr, diff, num_flips)
				ans.append(index + 1)
				num_flips += 1
				diff = index - diff
	answers.append(ans)
for ans in answers:
	print(len(ans), end=' ')
	print(*ans, sep=' ')


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


for _ in range(int(input())):
	n = int(input())
	a = input() + '0'
	b = input() + '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()
	l1.extend(l2)
	print(len(l1), *l1)


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

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

def LS():
	return [i for i in input().split()]

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

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 2305843009213693951
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Comb:

	def __init__(self, n, mo=10 ** 9 + 7):
		self.fac = [0] * (n + 1)
		self.inv = [1] * (n + 1)
		self.fac[0] = 1
		self.fact(n)
		for i in range(1, n + 1):
			self.fac[i] = i * self.fac[i - 1] % mo
			self.inv[n] *= i
			self.inv[n] %= mo
		self.inv[n] = pow(self.inv[n], mo - 2, mo)
		for i in range(1, n):
			self.inv[n - i] = self.inv[n - i + 1] * (n - i + 1) % mo
		return

	def fact(self, n):
		return self.fac[n]

	def invf(self, n):
		return self.inv[n]

	def comb(self, x, y):
		if y < 0 or y > x:
			return 0
		return self.fac[x] * self.inv[x - y] * self.inv[y] % mo
show_flg = False
show_flg = True
ans = 0

def make0(s):
	n = len(s)
	s += [0]
	rt = []
	for i in range(n):
		if s[i] != s[i + 1]:
			rt += (i + 1,)
	return rt
for _ in range(I()):
	n = I()
	s = [int(i) for i in input()]
	t = [int(i) for i in input()]
	ans = 0
	(rs, rt) = (make0(s), make0(t))
	ans = rs + rt[::-1]
	print(len(ans), *ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	s1 = list(map(int, input()))
	s2 = list(map(int, input()))
	ans = []
	start = 0
	end = n - 1
	flipped = 0
	for i in range(n - 1, -1, -1):
		if end > start:
			if s1[end] == s2[i]:
				end -= 1
				continue
			if s1[start] == s2[i]:
				ans.append(1)
				s1[start] = 1 - s1[start]
			ans.append(i + 1)
			(end, start) = (start, end)
			end += 1
			flipped += 1
		elif end < start:
			if 1 - s1[end] == s2[i]:
				end += 1
				continue
			if 1 - s1[start] == s2[i]:
				ans.append(1)
				s1[start] = 1 - s1[start]
			ans.append(i + 1)
			(end, start) = (start, end)
			end -= 1
			flipped += 1
		elif flipped % 2 ^ s1[end] != s2[i]:
			ans.append(i + 1)
	print(len(ans), *ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input()))
	b = list(map(int, input()))
	(l, r) = (0, n - 1)
	f = 0
	o = []
	while l != r:
		k = abs(r - l)
		if a[r] ^ f != b[k]:
			if a[l] ^ f == b[k]:
				o += (1,)
			o += (k + 1,)
			f ^= 1
			l += 1 if r > l else -1
			(l, r) = (r, l)
		else:
			r += -1 if r > l else 1
	if a[l] ^ f != b[0]:
		o += (1,)
	print(len(o), *o)


import sys
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))
for _ in range(II()):
	(n, a, b) = (II(), SI() + '0', SI() + '0')
	(one, two) = ([], [])
	for i in range(n):
		if a[i + 1] != a[i]:
			one.append(i + 1)
		if b[i + 1] != b[i]:
			two.append(i + 1)
	ans = one + two[::-1]
	print(len(ans), *ans)


def flip(a, flip):
	if flip % 2 == 0:
		return a
	elif a == 1:
		return 0
	else:
		return 1
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 = []
	flipp = 0
	while j >= 0:
		if flip(a[i], flipp) != b[j]:
			ans.append(j + 1)
		else:
			ans.append(1)
			ans.append(j + 1)
		flipp += 1
		if i == 0:
			a.pop(0)
			i = j - 1
		else:
			a.pop()
			i = 0
		j -= 1
	ans.insert(0, len(ans))
	print(*ans)


import math
value = int(input())
for T in range(value):
	n = int(input())
	sa = input()
	sb = input()
	(count, ans) = (0, [])
	for i in range(0, n):
		j = -i - 1
		k = n - 1 - 2 * i
		if k == 0 and sb[0] != sa[i]:
			count += 1
			ans.append(1)
		if k <= 0:
			break
		if sa[i] == sb[k]:
			count += 1
			ans.append(1)
		count += 1
		ans.append(k + 1)
		if sa[j] != sb[k - 1]:
			count += 1
			ans.append(1)
		count += 1
		ans.append(k)
	print(count, end=' ')
	for v in ans:
		print(v, end=' ')
	print('')


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict
from bisect import bisect_left as bl, bisect_right as br
from collections import Counter
from collections import deque
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
t = ip()
for _ in range(t):
	n = ip()
	a = ips()
	b = ips()
	ch1 = []
	ch2 = []
	a += '0'
	b += '0'
	for i in range(1, n + 1):
		if a[i - 1] != a[i]:
			ch1.append(i)
		if b[i - 1] != b[i]:
			ch2.append(i)
	ch2 = ch2[::-1]
	ans = ch1 + ch2
	ans = [len(ans)] + ans
	print(*ans)


from _collections import deque
for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	c = []
	ans = 0
	for i in range(1, n):
		if a[i - 1] is not a[i]:
			c.append(i)
			ans += 1
	if a[-1] is not b[-1]:
		c.append(n)
		ans += 1
	for i in range(n - 2, -1, -1):
		if b[i] is not b[i + 1]:
			c.append(i + 1)
			ans += 1
	print(ans, end=' ')
	for i in c:
		print(i, end=' ')
	print()


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


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


from collections import deque
for _ in range(int(input())):
	n = int(input())
	a = list(input().strip())
	b = list(input().strip())
	an = []
	(sw, top, x) = (0, 0, deque(range(n)))
	for i in range(n - 1, -1, -1):
		if sw % 2 == 0:
			comp = x[-1]
			top = x[0]
			if str(int(a[comp]) ^ sw % 2) != b[i]:
				x.popleft()
				sw += 1
				if a[top] != a[comp]:
					an.append(1)
				an.append(i + 1)
			else:
				x.pop()
		else:
			comp = x[0]
			top = x[-1]
			if str(int(a[comp]) ^ sw % 2) != b[i]:
				x.pop()
				sw += 1
				if str(int(a[top]) ^ sw % 2) != str(int(a[comp]) ^ sw % 2):
					an.append(1)
				an.append(i + 1)
			else:
				x.popleft()
	print(len(an), *an)


from sys import stdin
input = lambda : stdin.readline().strip()
lin = lambda : list(map(int, input().split()))
iin = lambda : int(input())
main = lambda : map(int, input().split())
from math import ceil, sqrt, factorial, log
from collections import deque
from bisect import bisect_left
mod = 998244353
mod = 1000000007

def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while a % b != 0:
		(a, b) = (b, a % b)
	return b

def moduloinverse(a):
	return pow(a, mod - 2, mod)

def solve(we):
	n = iin()
	a = list(input())
	b = list(input())
	t = -1
	ans = []
	a = a + ['0']
	for i in range(n + 1):
		if a[i] == '0':
			if t != -1 and t < i - 1:
				ans.append(t + 1)
				ans.append(i)
			elif t == -1 and i != 0:
				ans.append(i)
			t = i
	t = '0'
	for i in range(n - 1, -1, -1):
		if b[i] != t:
			ans.append(i + 1)
			if t == '1':
				t = '0'
			else:
				t = '1'
	print(str(len(ans)), *ans)
qwe = 1
qwe = iin()
for _ in range(qwe):
	solve(_ + 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(b) for b in input()]
	valb = [int(b) for b in input()]
	outy = []
	flips = 0
	adj = 0
	for s in range(n - 1, -1, -1):
		if flips % 2 == 0:
			ind = adj + s
			if (vala[ind] + flips) % 2 == valb[s]:
				continue
			else:
				ind0 = adj
				if (vala[ind0] + flips) % 2 != valb[s]:
					if flips % 2 == 0:
						adj += s
					else:
						adj -= s
				else:
					if flips % 2 == 0:
						adj += s
					else:
						adj -= s
					outy.append(1)
				outy.append(s + 1)
				flips += 1
		else:
			ind = adj - s
			if (vala[ind] + flips) % 2 == valb[s]:
				continue
			else:
				ind0 = adj
				if (vala[ind0] + flips) % 2 != valb[s]:
					if flips % 2 == 0:
						adj += s
					else:
						adj -= s
				else:
					if flips % 2 == 0:
						adj += s
					else:
						adj -= s
					outy.append(1)
				outy.append(s + 1)
				flips += 1
	outy = [len(outy)] + outy
	print(*outy)


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

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

def solve():
	n = ri()
	s = list(map(int, input()))
	t = list(map(int, input()))
	moves = []
	prev_flip = n - 1
	rng = [0, n - 1]

	def UPDATE(pos, prev_flip, rng):
		d = prev_flip - pos
		prev_flip = pos
		(a, b) = rng
		if a < b:
			rng = [b - d, a]
		else:
			rng = [b + d, a]
		return (prev_flip, rng)

	def STATUS(pos, rng):
		(a, b) = rng
		if a <= b:
			orig = s[a + pos]
			return orig
		else:
			orig = s[a - pos]
			return 1 - orig
	for pos in range(n - 1, 0, -1):
		if STATUS(pos, rng) == t[pos]:
			continue
		elif STATUS(0, rng) != t[pos]:
			moves.append(pos + 1)
			(prev_flip, rng) = UPDATE(pos, prev_flip, rng)
		else:
			moves.append(1)
			moves.append(pos + 1)
			(prev_flip, rng) = UPDATE(pos, prev_flip, rng)
	if STATUS(0, rng) != t[0]:
		moves.append(1)
	print(len(moves), *moves)
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


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

def solve(N, A, B):

	def f(A):
		p = []
		front = []
		i = 0
		while i < N:
			x = A[i]
			if not front:
				front.append([x, 1])
			elif front[-1][0] != x:
				if len(front) == 1:
					front.append([x, 1])
				else:
					assert len(front) == 2
					p.append(front[0][1])
					front[0][0] ^= 1
					front[0][1] = front[0][1] + front[1][1]
					front[1][0] = x
					front[1][1] = 1
					assert front[0][0] != front[1][0]
			else:
				assert front[-1][0] == x
				front[-1][1] += 1
			i += 1
		if len(front) == 2:
			p.append(front[0][1])
			front[0][0] ^= 1
		return (front[0][0], p)
	(parity1, p1) = f(A)
	(parity2, p2) = f(B)
	if parity1 != parity2:
		p1.append(N)
	p2 = deque(p2)
	while p1 and p2 and (p1[-1] == p2[-1]):
		p1.pop()
		p2.pop()
	p2 = list(p2)[::-1]
	return str(len(p1) + len(p2)) + ' ' + ' '.join([str(x) for x in p1 + p2])
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	A = list(map(int, input().decode().rstrip()))
	B = list(map(int, input().decode().rstrip()))
	ans = solve(N, A, B)
	print(ans)


from collections import deque

def f(v):
	if v == '1':
		return '0'
	else:
		return '1'

def e(x):
	if x % 2 == 0:
		return a[x // 2]
	else:
		return f(a[-(x // 2 + 1)])
for _ in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	m = []
	i = 1
	while i <= n:
		if e(i - 1) == b[-i]:
			m.append(1)
			m.append(n - i + 1)
		else:
			m.append(n - i + 1)
		i += 1
	print(len(m), *m)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	al = 0
	ah = len(a) - 1
	ac = len(a) - 1
	ao = 0
	is_flipped = False
	res = []
	for (i, c) in enumerate(reversed(b)):
		if (c == a[ac]) ^ is_flipped:
			if ac == ah:
				ah -= 1
				ac -= 1
			else:
				al += 1
				ac += 1
			continue
		if (c != a[ao]) ^ is_flipped:
			res.append(ah - al + 1)
			if ac == ah:
				(ac, ao) = (ao, ac)
				ac += 1
				al += 1
			else:
				(ac, ao) = (ao, ac)
				ac -= 1
				ah -= 1
			is_flipped = not is_flipped
			continue
		else:
			res.append(1)
			res.append(ah - al + 1)
			if ac == ah:
				(ac, ao) = (ao, ac)
				ac += 1
				al += 1
			else:
				(ac, ao) = (ao, ac)
				ac -= 1
				ah -= 1
			is_flipped = not is_flipped
			continue
	print(len(res), *res)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		a = [int(c) for c in S()]
		b = [int(c) for c in S()]
		l = 0
		r = n - 1
		sf = 0
		t = []
		for i in range(n - 1, 0, -1):
			c = b[i]
			if sf:
				if a[l] != c:
					l += 1
				else:
					if a[r] != c:
						t.append(1)
					t.append(i + 1)
					r -= 1
					sf = 0
			elif a[r] == c:
				r -= 1
			else:
				if a[l] == c:
					t.append(1)
				t.append(i + 1)
				l += 1
				sf = 1
		c = b[0]
		if sf and a[r] == c or (not sf and a[l] != c):
			t.append(1)
		rr.append(JA([len(t)] + t, ' '))
	return JA(rr, '\n')
print(main())


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


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 = []
	cnt = 0
	x = 0
	y = n - 1
	for i in range(n - 1, -1, -1):
		if cnt % 2 == 0:
			if b[i] == '1':
				if a[x] == '1':
					c.append(1)
					c.append(i + 1)
				else:
					c.append(i + 1)
			elif a[x] == '0':
				c.append(1)
				c.append(i + 1)
			else:
				c.append(i + 1)
			x += 1
		else:
			if b[i] == '1':
				if a[y] == '0':
					c.append(1)
					c.append(i + 1)
				else:
					c.append(i + 1)
			elif a[y] == '1':
				c.append(1)
				c.append(i + 1)
			else:
				c.append(i + 1)
			y -= 1
		cnt += 1
	print(len(c), end=' ')
	for i in c:
		print(i, end=' ')
	print()


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)


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


class Solution:

	def __init__(self, debug=False, n=None, a=None, b=None):
		if n is None:
			(n, a, b) = Solution.input()
		self.n = n
		self.a = a
		self.b = b
		self.real = [x for x in self.a]
		self.inverse = [not x for x in self.a]
		self.curr_zero = 0
		self.curr_last = self.n - 1
		self.real_idx = self.n - 1
		self.inv = False
		self.debug = debug
		if debug:
			self.current_state = [x for x in self.a]
		self.operations = [self.n + 1000]

	@staticmethod
	def input():
		n = int(input())
		a = [x == '1' for x in input()]
		b = [x == '1' for x in input()]
		return (n, a, b)

	def iteration(self):
		if self.inv:
			if self.inverse[self.curr_last] != self.b[self.real_idx]:
				if self.inverse[self.curr_zero] != self.inverse[self.curr_last]:
					self.operation(0)
					(self.real[self.curr_zero], self.inverse[self.curr_zero]) = (self.inverse[self.curr_zero], self.real[self.curr_zero])
				self.operation(self.real_idx)
				self.inv = False
				(self.curr_zero, self.curr_last) = (self.curr_last, self.curr_zero)
		elif self.real[self.curr_last] != self.b[self.real_idx]:
			if self.real[self.curr_zero] != self.real[self.curr_last]:
				self.operation(0)
				(self.real[self.curr_zero], self.inverse[self.curr_zero]) = (self.inverse[self.curr_zero], self.real[self.curr_zero])
			self.operation(self.real_idx)
			self.inv = True
			(self.curr_zero, self.curr_last) = (self.curr_last, self.curr_zero)
		if self.inv:
			self.curr_last += 1
		else:
			self.curr_last -= 1
		self.real_idx -= 1

	def solve(self):
		while self.real_idx >= 0:
			self.iteration()
		return self.return_answer()

	def special_cases(self):
		if self.n == 1:
			if self.a[0] != self.b[0]:
				self.operation(0)
			return self.return_answer

	def operation(self, i):
		self.operations.append(i + 1)
		if self.debug:
			self.current_state[:i + 1] = [not x for x in self.current_state[:i + 1]][::-1]
		if self.n < 2:
			return

	def return_answer(self):
		if self.debug:
			assert all((x == y for (x, y) in zip(self.b, self.current_state)))
		ans = f"{len(self.operations) - 1} {' '.join((str(x) for x in self.operations[1:]))}"
		print(ans)
		return ans

def solve():
	n = int(input())
	a = [int(x) for x in input()]
	b = [int(x) for x in input()]
	real = [x for x in a]
	inverse = [(x + 1) % 2 for x in a]
	inv_idx = 0
	real_idx = n - 1
	inv = False
	operations = []
	seq = []
	while real_idx > 0:
		if not inv:
			if real[real_idx] == b[real_idx]:
				real_idx -= 1
				inv_idx += 1
				seq.append(real[real_idx])
				continue
			if real[0] != real[real_idx]:
				operations.append(1)
				(real[0], inverse[-1]) = (inverse[-1], real[0])
			operations.append(real_idx + 1)
			real[real_idx] = b[real_idx]
			seq.append(real[real_idx])
			inverse[inv_idx] = (real[real_idx] + 1) % 2
			inv = True
		else:
			if inverse[inv_idx] == b[real_idx]:
				real_idx -= 1
				inv_idx += 1
				seq.append(inverse[inv_idx])
				continue
			if inverse[-1] != inverse[inv_idx]:
				operations.append(1)
				(real[0], inverse[-1]) = (inverse[-1], real[0])
			operations.append(real_idx + 1)
			inverse[inv_idx] = b[real_idx]
			real[real_idx] = (b[real_idx] + 1) % 2
			seq.append(inverse[inv_idx])
			inv = False
		real_idx -= 1
		inv_idx += 1
	if inv and inverse[-1] != b[0] or (real[0] != b[0] and (not inv)):
		operations.append(1)
	seq.append(b[0])
	print(seq, b)
	print(len(operations), *operations)
for _ in range(int(input())):
	(n, a, b) = Solution.input()
	Solution(False, n, a, b).solve()


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	flag = 0
	lft = 0
	rht = n - 1
	res = []
	for i in range(n - 1, -1, -1):
		if flag == 0:
			if b[i] == a[lft]:
				res.append(1)
			lft += 1
		else:
			if b[i] != a[rht]:
				res.append(1)
			rht -= 1
		res.append(i + 1)
		flag = 1 - flag
	print(len(res), *res)


for _ in range(int(input())):
	n = int(input())
	s = input()
	b = input()
	A = []
	for i in range(n - 1):
		if s[i] != s[i + 1]:
			A.append(i + 1)
	if s[-1] == '1':
		A.append(n)
	A1 = []
	for i in range(n - 1):
		if b[i] != b[i + 1]:
			A1.append(i + 1)
	if b[-1] == '1':
		A1.append(n)
	A += A1[::-1]
	print(len(A), *A)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	aToAllOnesOrZeros = []
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			aToAllOnesOrZeros.append(i + 1)
	bToAllOnesOrZeros = []
	for i in range(n - 1):
		if b[i] != b[i + 1]:
			bToAllOnesOrZeros.append(i + 1)
	res = aToAllOnesOrZeros
	if a[-1] != b[-1]:
		res.append(n)
	for i in range(len(bToAllOnesOrZeros) - 1, -1, -1):
		res.append(bToAllOnesOrZeros[i])
	l = len(res)
	res.insert(0, l)
	print(' '.join([str(x) for x in res]))


def convert_to_1(s):
	L = []
	for i in range(len(s) - 1):
		if s[i] != s[i + 1]:
			L.append(i + 1)
	if s[-1] == '0':
		L.append(len(s))
	return L
for i in ' ' * int(input()):
	n = int(input())
	s1 = input()
	s2 = input()
	L1 = convert_to_1(s1)
	L2 = convert_to_1(s2)
	L = L1 + L2[::-1]
	print(len(L), end=' ')
	for i in L:
		print(i, end=' ')
	print()


import sys, math
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input().strip()

def listStr():
	return list(input().strip())
import collections as col
import math

def rev(arr):
	return arr[::-1]

def comp(arr):
	return [arr[j] ^ 1 for j in range(len(arr))]

def RC(arr):
	return rev(comp(arr))

def solve():
	N = getInt()
	S1 = [int(s) for s in input().strip()]
	S2 = [int(s) for s in input().strip()]
	index = N - 1
	ans = []
	parity = 1
	curr_max = N - 1
	curr_min = 0
	checker = []
	while index > -1:
		targ = S2[index]
		ref = S1[curr_min] if parity > 0 else 1 - S1[curr_max]
		if index == 0:
			if ref != S2[index]:
				ans.append(1)
				if parity > 0:
					S1[curr_min] = 1 - S1[curr_min]
				else:
					S1[curr_max] = 1 - S1[curr_max]
		elif ref != targ:
			ans.append(index + 1)
		else:
			ans.append(1)
			if parity > 0:
				S1[curr_min] = 1 - S1[curr_min]
			else:
				S1[curr_max] = 1 - S1[curr_max]
			ans.append(index + 1)
		parity *= -1
		index -= 1
		if parity < 0:
			curr_min += 1
		else:
			curr_max -= 1
	print(len(ans), *ans)
	return
for _ in range(getInt()):
	solve()


import sys
input = sys.stdin.readline
from collections import deque
t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	q = deque([i for i in range(n)])
	rev = False
	ans = []
	for i in range(n)[::-1]:
		if rev:
			a_ind = q[0]
			if a[a_ind] != b[i]:
				q.popleft()
				continue
			else:
				if a[q[-1]] == b[i]:
					ans.append(i + 1)
				else:
					ans.append(1)
					ans.append(i + 1)
				q.pop()
				rev = False
		else:
			a_ind = q[-1]
			if a[a_ind] == b[i]:
				q.pop()
				continue
			else:
				if a[q[0]] != b[i]:
					ans.append(i + 1)
				else:
					ans.append(1)
					ans.append(i + 1)
				q.popleft()
				rev = True
	print(len(ans), *ans)


for _ in range(int(input())):
	n = int(input())
	l1 = list(map(int, input()))
	l2 = list(map(int, input()))
	flip = False
	idx = 0
	ans = []
	for i in range(n - 1, -1, -1):
		if flip ^ (l1[idx] == l2[i]):
			ans.append(1)
		ans.append(i + 1)
		if flip:
			idx -= i
		else:
			idx += i
		flip = not flip
	print(len(ans), *ans)


import os
import sys
input = sys.stdin.readline
from collections import deque
from queue import PriorityQueue
import math
import copy

class AC(object):

	def fan(self, s, pos):
		for i in range(pos + 1):
			if s[i] == '0':
				s[i] = '1'
			else:
				s[i] = '0'
		pass

	def __init__(self):
		t = int(input())
		for _ in range(t):
			n = int(input())
			a = deque(input())
			if len(a) > n:
				a.pop()
			b = list(input())
			ans = []
			now = 0
			sign = 0
			for pos in range(n)[::-1]:
				if sign == 0:
					if b[pos] == a[now]:
						ans.append(1)
				elif b[pos] != a[now]:
					ans.append(1)
				pass
				if now == 0:
					a.popleft()
				else:
					a.pop()
				ans.append(pos + 1)
				sign = 1 - sign
				now = -1 - now
			pass
			print(len(ans), end=' ')
			print(' '.join(map(str, ans)))
		pass

	def main(self):
		pass
ac = AC()
ac.main()
pass


for _ in range(int(input())):
	n = int(input())
	s = input()
	s += '0'
	t = input()
	t += '0'
	t = t[::-1]
	result = []
	for i in range(n):
		if s[i] != s[i + 1]:
			result.append(i + 1)
	for j in range(n):
		if t[j] != t[j + 1]:
			result.append(n - j)
	print(len(result), *result)


t = int(input())
for _ in range(t):
	n = int(input())
	list1 = list(map(int, input()))
	list2 = list(map(int, input()))
	ans = []
	start = 0
	invert = 0
	for i in range(n - 1, 0 - 1, -1):
		aim = list2[i]
		if invert % 2 == 0 and list1[start + i] == aim or (invert % 2 != 0 and list1[start - i] != aim):
			continue
		if invert % 2 == 0 and list1[start] == aim or (invert % 2 != 0 and list1[start] != aim):
			ans.append(1)
			ans.append(i + 1)
		else:
			ans.append(i + 1)
		if invert % 2 == 0:
			start = start + i
		else:
			start = start - i
		invert += 1
	print(len(ans), end=' ')
	for val in ans:
		print(val, end=' ')
	print()


import sys
input = lambda : sys.stdin.readline().rstrip()
from collections import deque
from queue import LifoQueue
for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	a1 = []
	a2 = []
	for i in range(0, n, 2):
		if a[i:i + 2] == '01':
			a1.append(i + 1)
			a1.append(i + 2)
		elif a[i:i + 2] == '10':
			if i != 0:
				a1.append(i)
			a1.append(i + 1)
		elif a[i:i + 2] == '11':
			if i != 0:
				a1.append(i)
			a1.append(i + 2)
		elif a[i:i + 2] == '1':
			if n - 1 > 0:
				a1.append(n - 1)
			a1.append(n)
	for i in range(0, n, 2):
		if b[i:i + 2] == '01':
			a2.append(i + 1)
			a2.append(i + 2)
		elif b[i:i + 2] == '10':
			if i != 0:
				a2.append(i)
			a2.append(i + 1)
		elif b[i:i + 2] == '11':
			if i != 0:
				a2.append(i)
			a2.append(i + 2)
		elif b[i:i + 2] == '1':
			if n - 1 > 0:
				a2.append(n - 1)
			a2.append(n)
	a2.reverse()
	c = a1 + a2
	for i in range(len(c) - 1):
		if c[i] == c[i + 1]:
			c.pop(i)
			c.pop(i)
			break
	print(len(c), *c)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().strip()))
	b = list(map(int, input().strip()))
	(ans1, ans2) = ([], [])
	if a.count(1) > n // 2:
		for i in range(n):
			a[i] = 1 * (a[i] == 0)
		a.reverse()
		ans1.append(n)
	for i in range(n):
		if a[i] == 1:
			if i != 0:
				ans1.append(i)
			ans1.append(i + 1)
	if b.count(1) > n // 2:
		for i in range(n):
			b[i] = 1 * (b[i] == 0)
		b.reverse()
		ans2.append(n)
	for i in range(n):
		if b[i] == 1:
			if i != 0:
				ans2.append(i)
			ans2.append(i + 1)
	print(len(ans1) + len(ans2), *ans1, *ans2[::-1])


t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	s1 = input()
	s2 = input()
	l = 0
	r = n - 1
	rev = False
	ans = []
	for x in s2[-1::-1]:
		if not rev:
			if s1[r] == x:
				r -= 1
				continue
			if s1[l] == x:
				ans.append(1)
			ans.append(r - l + 1)
			l += 1
			rev = True
		else:
			if s1[l] != x:
				l += 1
				continue
			if s1[r] != x:
				ans.append(1)
			ans.append(r - l + 1)
			r -= 1
			rev = False
	print(len(ans))
	for x in ans:
		print(x, end=' ')
	print()


from sys import stdin
from collections import defaultdict
input = stdin.readline
T = int(input())
for t in range(1, T + 1):
	n = int(input())
	s = input()
	res = []
	a = [0] * (n + 1)
	b = [0] * (n + 1)
	for i in range(1, n + 1):
		a[i] = int(s[i - 1])
	s = input()
	for i in range(1, n + 1):
		b[i] = int(s[i - 1])
	(l, r, cal) = (1, n, 0)
	for h in range(1, n + 1):
		if a[l] ^ cal == b[n + 1 - h]:
			a[l] ^= 1
			res.append(1)
		if l <= r:
			res.append(r - l + 1)
			l += 1
		else:
			res.append(l - r + 1)
			l -= 1
		(l, r) = (r, l)
		cal ^= 1
	print(len(res), end=' ')
	for x in res:
		print(x, end=' ')
	print()


import os
import sys
from io import BytesIO, IOBase

def main():
	pass
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 count1(s):
	c = 0
	for i in s:
		if i == '1':
			c += 1
	return c

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True
for xyz in range(0, int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	s1 += '1'
	s2 += '1'
	p1 = []
	for i in range(0, n):
		if s1[i] != s1[i + 1]:
			p1.append(i + 1)
	p2 = []
	for i in range(0, n):
		if s2[i] != s2[i + 1]:
			p2.append(i + 1)
	p2.reverse()
	p1 += p2
	print(len(p1), *p1)


def task():
	n = int(input())
	a = input()
	b = input()
	answer = []
	j = len(b) - 1
	for i in range(len(a)):
		if i % 2 == 0:
			i1 = i // 2
		else:
			i1 = n - 1 - i // 2
		c = a[i1]
		if i % 2 != 0:
			c = '0' if c == '1' else '1'
		if c == b[j]:
			answer.append(1)
		answer.append(j + 1)
		j -= 1
	print(len(answer), end=' ')
	print(*answer)
n = int(input())
for _ in range(n):
	task()


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write
t = int(fastinput())

def changeflag(flag):
	return 0 if flag == 1 else 1

def original(c, flag):
	if flag == 1:
		return c
	else:
		return '0' if c == '1' else '1'

def ismatch(c, v, flag):
	c = original(c, flag)
	if c == v:
		return True
	else:
		return False
while t:
	t -= 1
	n = int(fastinput())
	a = input()
	b = input()
	start = 0
	end = n - 1
	flag = 1
	instruction = []
	for i in range(n - 1, -1, -1):
		if start == end:
			if ismatch(a[start], b[i], flag):
				continue
			else:
				instruction.append(1)
		elif start < end:
			if ismatch(a[end], b[i], flag):
				end -= 1
			else:
				if ismatch(a[start], b[i], flag):
					instruction.append(1)
				flag = changeflag(flag)
				instruction.append(end - start + 1)
				temp = start
				start = end
				end = temp
				end += 1
		elif ismatch(a[end], b[i], flag):
			end += 1
		else:
			if ismatch(a[start], b[i], flag):
				instruction.append(1)
			instruction.append(start - end + 1)
			flag = changeflag(flag)
			temp = start
			start = end
			end = temp
			end -= 1
	print(len(instruction), *instruction)


t = int(input())
for i in range(t):
	n = int(input())
	a = str(input())
	b = str(input())
	a = a + '0'
	b = b + '0'
	ans1 = []
	ans2 = []
	for j in range(1, n + 1):
		if a[j] != a[j - 1]:
			ans1.append(j)
		if b[j] != b[j - 1]:
			ans2.append(j)
	l = len(ans2)
	for j in range(1, l + 1):
		ans1.append(ans2[-j])
	k = len(ans1)
	lis = [k]
	for j in range(k):
		lis.append(ans1[j])
	print(' '.join((str(x) for x in lis)))


t = int(input())
while t:
	t -= 1
	n = int(input())
	l1 = input()
	l2 = input()
	ans = []
	revert = False
	index = -1
	for i in range(n):
		if i % 2 == 0:
			index += 1
			c1 = index
		else:
			c1 = n - index - 1
		if l1[c1] != l2[n - i - 1]:
			if i % 2 == 0:
				ans.append(n - i)
			else:
				ans.append(1)
				ans.append(n - i)
		elif i % 2 == 0:
			ans.append(1)
			ans.append(n - i)
		else:
			ans.append(n - i)
	print(len(ans), end=' ')
	print(*ans)


for _ in range(int(input())):
	n = int(input())
	a = []
	b = []
	a1 = list(input())
	b1 = list(input())
	for i in a1:
		a.append(int(i))
	for i in b1:
		b.append(int(i))
	pos1 = 0
	pos2 = n - 1
	reverse = 0
	ans = []
	for i in range(n - 1, -1, -1):
		if not reverse:
			if a[pos1] == b[i]:
				ans.append(1)
			ans.append(i + 1)
			reverse = 1
			pos1 += 1
		else:
			if a[pos2] != b[i]:
				ans.append(1)
			ans.append(i + 1)
			reverse = 0
			pos2 -= 1
	print(len(ans), end=' ')
	for i in ans:
		print(i, end=' ')
	print()


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


(z, zz) = (input, lambda : list(map(int, z().split())))
fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
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
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

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 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = 1
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	n = int(z())
	T1 = fast()
	T2 = fast()
	out = []
	for i in range(n - 1):
		if T1[i] != T1[i + 1]:
			out.append(i + 1)
	curr = T1[-1]
	for i in range(n - 1, -1, -1):
		if T2[i] != curr:
			out.append(i + 1)
			curr = '0' if curr == '1' else '1'
	print(len(out), *out)


import collections
t1 = int(input())
for _ in range(t1):
	flipflag = 0
	bitflag = 0
	n = int(input())
	a2 = input()
	a = collections.deque([])
	for i in range(n):
		a.append(a2[i])
	b = input()
	ans = []
	for i in range(n - 1, -1, -1):
		if flipflag == 0:
			p = a[-1]
		else:
			p = a[0]
		if bitflag == 1:
			if p == '0':
				p = '1'
			else:
				p = '0'
		if flipflag == 0:
			q = a[0]
		else:
			q = a[-1]
		if bitflag == 1:
			if q == '0':
				q = '1'
			else:
				q = '0'
		if p != b[i]:
			if q != b[i]:
				ans.append(str(i + 1))
				if flipflag == 0:
					a.popleft()
				else:
					a.pop()
				flipflag = 1 - flipflag
				bitflag = 1 - bitflag
			else:
				ans.append('1')
				ans.append(str(i + 1))
				if flipflag == 0:
					a.popleft()
				else:
					a.pop()
				flipflag = 1 - flipflag
				bitflag = 1 - bitflag
		elif flipflag == 0:
			a.pop()
		else:
			a.popleft()
	print(len(ans))
	if len(ans) > 0:
		print(' '.join(ans))


for i in range(int(input())):
	n = int(input())
	a = input() + '0'
	b = input() + '0'
	aToZero = []
	bToZero = []
	for i in range(0, n):
		if a[i] != a[i + 1]:
			aToZero.append(i + 1)
		if b[i] != b[i + 1]:
			bToZero.append(i + 1)
	aToZero += bToZero[::-1]
	print(len(aToZero), end=' ')
	print(*aToZero)


import sys
import os, io
input = sys.stdin.readline

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

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

def print_list(l):
	print(' '.join(map(str, l)))
N = int(input())
for i in range(N):
	n = int(input())
	a = input().strip()
	b = input().strip()
	res = []
	rev = False
	(start, end) = (0, n - 1)
	for i in range(n - 1, -1, -1):
		if not rev:
			if b[i] == a[end]:
				end -= 1
			else:
				if b[i] == a[start]:
					res.append(1)
				res.append(i + 1)
				start += 1
				rev = not rev
		elif b[i] != a[start]:
			start += 1
		else:
			if b[i] != a[end]:
				res.append(1)
			res.append(i + 1)
			end -= 1
			rev = not rev
	print_list([len(res)] + res)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input()))
	b = list(map(int, input()))
	ans = []
	f = 0
	(l, r) = (0, n - 1)
	i = n - 1
	while l <= r:
		if f == 0:
			if a[r] ^ f != b[i]:
				if a[l] ^ f == b[i]:
					ans.append(1)
				ans.append(r - l + 1)
				f ^= 1
				l += 1
			else:
				r -= 1
		elif a[l] ^ f != b[i]:
			if a[r] ^ f == b[i]:
				ans.append(1)
			ans.append(r - l + 1)
			f ^= 1
			r -= 1
		else:
			l += 1
		i -= 1
	print(len(ans), *ans)


import os
t1 = int(input())
while t1:
	t1 -= 1
	n = int(input())
	s = input()
	t = input()
	s += '0'
	t += '0'
	ans = []
	for i in range(n):
		if s[i] != s[i + 1]:
			ans.append(i + 1)
	for i in range(n, 0, -1):
		if t[i] != t[i - 1]:
			ans.append(i)
	print(len(ans), end=' ')
	for x in ans:
		print(x, end=' ')
	print()


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
I = sys.stdin.readline

def ii():
	return int(I().strip())

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

def mi():
	return map(int, I().strip().split())

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

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

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def div(n):
	tmp = []
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			cnt = 0
			while n % i == 0:
				n = n // i
				cnt += 1
			tmp.append((i, cnt))
	if n > 1:
		tmp.append((n, 1))
	return tmp

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		flag = True
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				flag = False
				break
		return flag

def s(b):
	d = defaultdict(int)
	while b > 0:
		tmp = b % 10
		if d[tmp] > 0:
			return False
		d[tmp] = 1
		b = b // 10
	return True

def main():
	for _ in range(ii()):
		n = ii()
		s = I().strip()
		s2 = I().strip()
		ans = []
		for i in range(1, n):
			if s[i] != s[i - 1]:
				ans.append(i)
		if s[n - 1] == '1':
			ans.append(n)
		tmp = []
		for i in range(1, n):
			if s2[i] != s2[i - 1]:
				tmp.append(i)
		if s2[n - 1] == '1':
			tmp.append(n)
		ans += tmp[::-1]
		ans = [len(ans)] + ans
		print(*ans)
main()


def main(r):
	n = int(input())
	a = input()
	b = input()
	st = 0
	end = n - 1
	ln = 0
	swaps = ''
	if len(a) == 1:
		if a == b:
			print(0)
		else:
			print('1 1')
		return
	else:
		for i in range(0, n):
			if i % 2 == 0:
				if a[st] == b[-(1 + i)]:
					ln += 1
					swaps += '1 '
				st += 1
			else:
				if a[end] != b[-(1 + i)]:
					swaps += '1 '
					ln += 1
				end -= 1
			ln += 1
			swaps += str(n - i) + ' '
		print(ln, swaps)
t = int(input())
for i in range(t):
	main(i)


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
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')

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def fun(n, m):
	s1 = decimalToBinary(n)
	s2 = decimalToBinary(m)
	return abs(binaryToDecimal(s1 + s2) - binaryToDecimal(s2 + s1))
for xyz in range(0, int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	s1 += '1'
	s2 += '1'
	l1 = []
	l2 = []
	for i in range(0, n):
		if s1[i] != s1[i + 1]:
			l1.append(i + 1)
		if s2[i] != s2[i + 1]:
			l2.append(i + 1)
	l2.reverse()
	print(len(l1) + len(l2), *l1, *l2)


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	a = stdin.readline().strip()
	b = stdin.readline().strip()
	ans = []
	idx = 0
	flip = False
	for i in range(n - 1, -1, -1):
		if not flip and a[idx] == b[i] or (flip and a[idx] != b[i]):
			ans.append(1)
		ans.append(i + 1)
		if flip:
			idx -= i
		else:
			idx += i
		flip = not flip
	stdout.write(str(len(ans)) + ' ')
	if len(ans) > 0:
		stdout.write(' '.join(map(str, ans)) + '\n')


import math
from sys import stdin, stdout
for _ in range(int(input())):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	ans = []
	c = 0
	f = 0
	j = 0
	for i in range(n - 1, -1, -1):
		if f == 0:
			if s1[j] == s2[i]:
				ans.append(str(1))
				c += 1
		elif s1[j] != s2[i]:
			ans.append(str(1))
			c += 1
		ans.append(str(i + 1))
		c += 1
		if f == 0:
			f = 1
			k = n - 1 - j
			j = k
		else:
			f = 0
			k = n - 1 - j
			j = k + 1
	print(str(c) + ' ' + ' '.join(ans))


import sys
input = sys.stdin.readline
T = int(input())
for t in range(T):
	N = int(input())
	A = input()[:-1]
	B = input()[:-1]
	answer = []
	el0 = A[0]
	for i in range(N - 1, -1, -1):
		if el0 == B[i]:
			answer.append(1)
		answer.append(i + 1)
		if i == N - 1:
			el0 = '0' if A[i] == '1' else '1'
		elif (N - i) % 2:
			el0 = '0' if A[N - 1 - (N - i - 1) // 2] == '1' else '1'
		else:
			el0 = A[(N - i) // 2]
	print(len(answer), ' '.join(map(str, answer)))


import sys
from collections import deque
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = deque(input().rstrip())
	b = input().rstrip()
	ans = []
	cnt = 0
	for i in range(1, n)[::-1]:
		if cnt % 2 == 0:
			x = a.popleft()
		else:
			x = a.pop()
		if (cnt % 2 == 0) ^ (x == b[i]) == 0:
			ans.extend((1, i + 1))
		else:
			ans.append(i + 1)
		cnt += 1
	if (cnt % 2 == 0) ^ (a[0] == b[0]):
		ans.append(1)
	ansl = len(ans)
	print(ansl, *ans)


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


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


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	s = [int(item) for item in list(input().rstrip())]
	t = [int(item) for item in list(input().rstrip())]
	srev = []
	for item in s:
		srev.append(1 - item)
	ans = []
	state = 1
	for_idx = n - 1
	rev_idx = 0
	for i in range(n):
		ti = t[n - 1 - i]
		if state:
			si = s[for_idx]
			if ti == si:
				for_idx -= 1
				continue
			if ti == s[rev_idx]:
				ans.append(1)
			ans.append(n - i)
			rev_idx += 1
		else:
			si = srev[rev_idx]
			if ti == si:
				rev_idx += 1
				continue
			if ti == srev[for_idx]:
				ans.append(1)
			ans.append(n - i)
			for_idx -= 1
		state = 1 - state
	if state:
		if s[rev_idx] != t[0]:
			ans.append(1)
	elif srev[for_idx] != t[0]:
		ans.append(1)
	if not ans:
		print(0)
	else:
		print(len(ans), *ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	ans = []
	cur = a[0]
	inv = 0
	in0 = 0
	arr = [0] * n
	ar1 = [i for i in range(1, (n + 1) // 2 + 1)]
	ar2 = [i for i in range(n, (n + 1) // 2, -1)]
	na = []
	for i in range(len(ar2)):
		na.append(ar1[i] - 1)
		na.append(ar2[i] - 1)
	if n % 2 == 1:
		na.append(ar1[-1] - 1)
	cnt = 0
	for i in range(n - 1, -1, -1):
		tmp = a[na[cnt]]
		if cnt % 2 == 1:
			cur = '0' if tmp == '1' else '1'
		else:
			cur = tmp
		if b[i] == cur:
			ans.append(1)
			ans.append(i + 1)
		else:
			ans.append(i + 1)
		inv += 1
		cnt += 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()
	i = 1
	s = a[0]
	ans = []
	while i < n:
		if a[i] == s[-1]:
			i += 1
			continue
		elif a[i] == '1' and s[-1] == '0':
			s = '1'
			ans.append(i)
		else:
			s = '0'
			ans.append(i)
		i += 1
	if s[-1] == '1':
		ans.append(n)
	i = 1
	s = b[0]
	ans2 = []
	while i < n:
		if b[i] == s[-1]:
			i += 1
			continue
		elif b[i] == '1' and s[-1] == '0':
			s = '1'
			ans2.append(i)
		else:
			s = '0'
			ans2.append(i)
		i += 1
	if s[-1] == '1':
		ans2.append(n)
	l = ans + ans2[::-1]
	print(len(l), *l)


from collections import deque
import sys

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

def slv():
	n = int(input())
	S = list(input())
	S = list(map(int, S))
	T = list(input())
	T = list(map(int, T))
	T.reverse()
	res = []
	idx_list = deque([i for i in range(n)])
	for i in range(n):
		if i % 2 == 0:
			idx = idx_list.popleft()
			num = S[idx] ^ 1
			if num == T[i]:
				res.append(n - i)
			else:
				res.append(1)
				res.append(n - i)
		else:
			idx = idx_list.pop()
			num = S[idx]
			if num == T[i]:
				res.append(n - i)
			else:
				res.append(1)
				res.append(n - i)
	L = len(res)
	res = [L] + res
	print(*res)
	return

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


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, list(input())))
	b = list(map(int, list(input())))
	ans = []
	a0 = a[0]
	j = n - 1
	k = 1
	for i in range(n - 1, -1, -1):
		if b[i] == a0:
			ans.append(1)
		ans.append(i + 1)
		if (n - i) % 2 == 1:
			a0 = (a[j] + 1) % 2
			j -= 1
		else:
			a0 = a[k]
			k += 1
	print(len(ans), *ans)


import sys, os, io

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 + '\n')

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		n = ri()
		a = rs()
		b = rs()
		s = ''
		if a == b:
			print(0)
			continue
		if n == 1:
			print(1, 1)
			continue
		ans1 = []
		ans2 = []
		z = 0
		c = 0
		for j in range(n):
			if a[j] == '0':
				break
			else:
				c += 1
		if c > 0:
			ans1.append(c)
		i = c
		while i < n:
			if a[i] == '1':
				if i - 1 >= 0:
					ans1.append(i)
					s = '1' * i
				if a[i:] == '1' * (n - len(s)):
					z = 1
					break
				for k in range(i, n):
					if a[k] == '0':
						break
				ans1.append(k)
				i = k + 1
			else:
				i += 1
		if z == 1:
			ans1.append(n)
		z = 0
		c = 0
		for j in range(n):
			if b[j] == '0':
				break
			else:
				c += 1
		if c > 0:
			ans2.append(c)
		i = c
		while i < n:
			if b[i] == '1':
				if i - 1 >= 0:
					ans2.append(i)
					s = '1' * i
				if b[i:] == '1' * (n - len(s)):
					z = 1
					break
				for k in range(i, n):
					if b[k] == '0':
						break
				ans2.append(k)
				i = k + 1
			else:
				i += 1
		if z == 1:
			ans2.append(n)
		print(len(ans1) + len(ans2), *ans1 + ans2[::-1])
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


production = True
import sys, math, collections

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for i in range(multi)]
	else:
		next_line = sys.stdin.readline()[:-1]
		if input_format >= 10:
			use_list = False
			input_format = int(str(input_format)[-1])
		else:
			use_list = True
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = list(next_line)
		elif input_format == 4:
			formatted_input = list(map(int, list(next_line)))
		elif input_format == 5:
			formatted_input = next_line.split()
		else:
			formatted_input = [next_line]
		return formatted_input if use_list else formatted_input[0]

def out(output_line, output_format=0, newline=True):
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 2:
		formatted_output = '\n'.join(map(str, output_line))
	print(formatted_output, end='\n' if newline else '')

def log(*args):
	if not production:
		print('$$$', end='')
		print(*args)
enu = enumerate
ter = lambda a, b, c: b if a else c
ceil = lambda a, b: -(-a // b)

def mapl(iterable, format=0):
	if format == 0:
		return list(map(int, iterable))
	elif format == 1:
		return list(map(str, iterable))
	elif format == 2:
		return list(map(list, iterable))

def f(a, l, r):
	k = [ter(i, 0, 1) for i in a[l:r]]
	return a[:l] + k[::-1] + a[r:]

def g(n):
	d = []
	t = 0
	for (i, j) in zip(range(n // 2 + 1), range(n - 1, n // 2 - 1, -1)):
		t += 1
		d.append((i, t & 1))
		if len(d) == n:
			break
		t += 1
		d.append((j, t & 1))
	return d

def solve():
	n = input(11)
	a = input(4)
	b = input(4)
	d = [(j, k, b[n - i - 1]) for (i, (j, k)) in enu(g(n))]
	s = []
	log(d)
	for (i, (j, k, bi)) in enu(d):
		r = int(k != a[j])
		if bi != r:
			s.append(1)
		s.append(n - i)
	out([len(s)] + s, 1)
	return
for i in range(input(11)):
	solve()


def get_flipped(x, flips):
	if flips % 2 == 0:
		return x
	else:
		return '0' if x == '1' else '1'

def solve():
	n = int(input().strip())
	a = input().strip()
	b = input().strip()
	ar = []
	for i in range(n):
		this_bit = b[n - i - 1]
		first_bit = get_flipped(a[i // 2] if i % 2 == 0 else a[n - 1 - i // 2], i)
		if first_bit == this_bit:
			ar.append(1)
		ar.append(n - i)
	print(len(ar), *ar)
t = int(input().strip())
for _ in range(t):
	solve()


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

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

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

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

def out(var):
	sys.stdout.write(str(var) + '\n')
from fractions import Fraction
INF = float('inf')
mod = int(1000000000.0) + 7
for t in range(int(data())):
	n = int(data())
	a = data()
	b = data()
	ind = n - 1
	ans = []
	i = 0
	k = -1
	for i in range(n - 1, -1, -1):
		if (n - 1 - i) % 2 == 0:
			if a[(n - i) // 2] == b[i]:
				ans.append(1)
			ans.append(i + 1)
		else:
			if a[n - (n - i) // 2] != b[i]:
				ans.append(1)
			ans.append(i + 1)
	print(str(len(ans)) + ' ' + ' '.join(map(str, ans)))


for _ in range(int(input())):
	n = int(input())
	a = input()
	l1 = list(a)
	b = input()
	l2 = list(b)
	t1 = []
	t2 = []
	i = 0
	while i < n:
		while i < n and l1[i] == '0':
			i += 1
		if i == n:
			break
		if i > 0:
			t1.append(i - 1)
		while i < n and l1[i] == '1':
			l1[i] = '0'
			i += 1
		t1.append(i - 1)
	i = 0
	while i < n:
		while i < n and l2[i] == '0':
			i += 1
		if i == n:
			break
		if i > 0:
			t2.append(i - 1)
		while i < n and l2[i] == '1':
			l2[i] = '0'
			i += 1
		t2.append(i - 1)
	t2.reverse()
	t = t1 + t2
	print(len(t), end=' ')
	for i in range(len(t)):
		print(t[i] + 1, end=' ')
	print()


import sys, os, io
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
import math

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

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

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

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

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

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

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
t = 1
t = int(input())
for _ in range(t):
	n = ii()
	a = list(si())
	b = list(si())
	i = 0
	j = n - 1
	ptr = n - 1
	rev = 0
	ans = []
	while i <= j and ptr >= 0:
		if rev == 0:
			if b[ptr] == a[i]:
				ans.append(1)
				rev = 1
				ans.append(ptr + 1)
				ptr -= 1
				i += 1
			else:
				rev = 1
				ans.append(ptr + 1)
				ptr -= 1
				i += 1
		elif b[ptr] != a[j]:
			ans.append(1)
			rev = 0
			ans.append(ptr + 1)
			ptr -= 1
			j -= 1
		else:
			rev = 0
			ans.append(ptr + 1)
			ptr -= 1
			j -= 1
	print(len(ans), *ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(input())
	b = list(input())
	ans = []
	l = 0
	r = n - 1
	for i in range(n - 1, -1, -1):
		if a[i] != b[i]:
			r = i
			break
	else:
		r = 0
	if l == r:
		if a[0] == b[0]:
			print(0)
		else:
			print(1, 1)
		continue
	else:
		flip = False
		count = r
		while l != r:
			if flip == False:
				if a[l] == b[count]:
					if a[l] == '0':
						a[l] = '1'
					else:
						a[l] = '0'
					ans.append(1)
					ans.append(count + 1)
				else:
					ans.append(count + 1)
				flip = True
			else:
				if a[r] != b[count]:
					if a[r] == '0':
						a[r] = '1'
					else:
						a[r] = '0'
					ans.append(1)
					ans.append(count + 1)
				else:
					ans.append(count + 1)
				flip = False
			for i in range(count, -1, -1):
				if flip == True:
					if a[l + count - i] == b[i]:
						l = l + count - i
						count = i
						break
				elif a[r - count + i] != b[i]:
					r = r - count + i
					count = i
					break
			else:
				if flip == False:
					l = r
				else:
					r = l
		if flip == False:
			if a[l] != b[0]:
				ans.append(1)
		elif a[r] == b[0]:
			ans.append(1)
		ans = [len(ans)] + ans
		print(*ans)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import Decimal
from decimal import *
from collections import defaultdict, deque
import heapq
from decimal import Decimal
getcontext().prec = 25
abcd = 'abcdefghijklmnopqrstuvwxyz'
ABCD = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
months = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31}
MOD = 1000000007
BUFSIZE = 8192
from bisect import bisect_left, bisect_right

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().rstrip()
	b = input().rstrip()
	out = []
	for i in range(n - 1):
		if i % 2 == 0:
			if b[n - i - 1] == a[i // 2]:
				out.append(1)
				out.append(n - i)
			else:
				out.append(n - i)
		elif b[n - i - 1] != a[n - i // 2 - 1]:
			out.append(1)
			out.append(n - i)
		else:
			out.append(n - i)
	if (n - 1) % 2 == 0:
		if a[(n - 1) // 2] != b[0]:
			out.append(1)
	elif a[n - (n - 1) // 2 - 1] == b[0]:
		out.append(1)
	print(len(out), *out)


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


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

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

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

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

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

def SI():
	return sys.stdin.readline()[:-1]
for _ in range(II()):
	n = II()
	a = SI()
	b = SI()
	ans = []
	l = 0
	r = n - 1
	rev = False
	for i in range(n - 1, 0, -1):
		if rev:
			if a[l] != b[i]:
				l += 1
				continue
			if a[r] != b[i]:
				ans.append(1)
			ans.append(i + 1)
			r -= 1
			rev = False
		else:
			if a[r] == b[i]:
				r -= 1
				continue
			if a[l] == b[i]:
				ans.append(1)
			ans.append(i + 1)
			l += 1
			rev = True
	if rev ^ (a[r] != b[0]):
		ans.append(1)
	print(len(ans), *ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(input())
	a = list(map(int, a))
	b = list(input())
	b = list(map(int, b))
	c = []
	lst1 = []
	i = 0
	j = n - 1
	idx = 0
	while len(c) < n:
		if idx % 2 == 0:
			c.append(a[i])
			i += 1
			idx += 1
		else:
			if a[j] == 0:
				c.append(1)
			else:
				c.append(0)
			j -= 1
			idx += 1
	ans = 0
	for i in range(n):
		if c[i] == b[n - i - 1]:
			ans += 2
			lst1.append(1)
			lst1.append(n - i)
		else:
			ans += 1
			lst1.append(n - i)
	print(ans, end=' ')
	for i in range(len(lst1)):
		print(lst1[i], end=' ')
	print()


def order(s):
	init = s[0]
	res = []
	for i in range(len(s) - 1):
		if s[i] != s[i + 1]:
			init = s[i + 1]
			res.append(i + 1)
	if init == '1':
		res.append(len(s))
	return res
for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	res = order(a) + order(b)[::-1]
	print(len(res), *res)


import sys
input = sys.stdin.readline
from collections import deque
t = int(input())
for tests in range(t):
	n = int(input())
	a = input().strip()
	b = input().strip()
	Q = deque(a)
	L = []
	while Q:
		L.append(Q.popleft())
		if Q:
			L.append(Q.pop())
	ANS = []
	for i in range(n):
		if i % 2 == 0:
			if L[i] == b[-1 - i]:
				ANS.append(1)
		elif L[i] != b[-1 - i]:
			ANS.append(1)
		ANS.append(n - i)
	print(len(ANS), *ANS)


from sys import stdin
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	a = stdin.readline().strip()
	b = stdin.readline().strip()
	out = []
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			out.append(i + 1)
	current = a[-1]
	for i in range(n - 1, -1, -1):
		if b[i] != current:
			out.append(i + 1)
			current = '0' if current == '1' else '1'
	print(len(out), end=' ')
	print(*out)


for _ in range(int(input())):
	n = int(input())
	arr = list(input())
	brr = list(input())
	a = 0
	b = n - 1
	k = 0
	ans = []
	for i in range(n - 1, -1, -1):
		if k == 0:
			if arr[a] == brr[i]:
				ans.append(1)
			ans.append(i + 1)
			k = 1
			a += 1
		else:
			if arr[b] != brr[i]:
				ans.append(1)
			ans.append(i + 1)
			k = 0
			b -= 1
	print(len(ans), *ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	ans = []
	st = a[0]
	for i in range(n - 1):
		if a[i] != a[i + 1]:
			ans.append(i + 1)
	if a[-1] == '1':
		ans.append(n)
	temp = []
	for i in range(n - 1):
		if b[i] != b[i + 1]:
			temp.append(i + 1)
	if b[-1] == '1':
		temp.append(n)
	ans = ans + temp[::-1]
	print(len(ans), *ans, sep=' ')


from sys import stdin
import sys
tt = int(input())
for loop in range(tt):
	n = int(input())
	a = input()
	b = input()
	if n == None:
		if a[0] == b[0]:
			print(0)
		else:
			print(1, 1)
		sys.exit()
	ind = [None] * n
	tmp = 0
	for i in range(n - 1, -1, -2):
		ind[i] = tmp
		tmp += 1
	if n % 2 == 0:
		for i in range(0, n, 2):
			ind[i] = tmp
			tmp += 1
	else:
		for i in range(1, n, 2):
			ind[i] = tmp
			tmp += 1
	ans = []
	x = 0
	for i in range(n - 1, -1, -1):
		if x == 0 and b[i] == a[ind[i]]:
			ans.append(1)
		elif x == 1 and b[i] != a[ind[i]]:
			ans.append(1)
		ans.append(i + 1)
		x ^= 1
	print(len(ans), *ans)


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)


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	ans = []
	sign = -1
	for ansi in range(n, 0, -1):
		if (a[(n + ansi * sign) // 2] == b[ansi - 1]) ^ (sign > 0):
			ans.append(1)
		ans.append(ansi)
		sign = -sign
	print(len(ans), *ans)


import sys
inp = sys.stdin.read().split()
ii = 0
t = int(inp[ii])
ii += 1
for _ in range(t):
	toprint = []
	n = int(inp[ii])
	ii += 1
	c = list(map(int, inp[ii]))
	ii += 1
	b = list(map(int, inp[ii]))
	ii += 1
	count = 0
	for i in range(n - 1, -1, -1):
		if count % 2 == 0:
			lead = c[count // 2]
		else:
			lead = 1 - c[-count // 2]
		y = b[i]
		if i == 0:
			if lead == y:
				pass
			else:
				toprint.append(1)
		else:
			if lead == y:
				toprint.append(1)
			toprint.append(i + 1)
		count += 1
	print(len(toprint), ' '.join(list(map(str, toprint))))