#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define see(x) cout<< #x <<" = "<< x <<' ';
#define seen(x) cout<< #x <<" = "<< x <<'\n';
#define UWU cout<<'\n';
ll Q;
void flip(int L,int R,string &s){
    string z = s.substr(L,R-L+1);
    for(int i = 0 ; i < z.size() ; ++i){
        (z[i] == '1' ? z[i] = '0' : z[i] = '1');
    }
    int j = 0;
    reverse(z.begin(),z.end());
    for(int i = L ; i <= R ; ++i){
        s[i] = z[j];
        j++;
    }
}
void solve(){
    int n;cin>>n;
    string s,x;cin>>s>>x;
    vector<int> ve;
    int p = n - 1;
    //transform to full zero
    while(p >= 0){
        if(s[p] == '0'){
            p--;
            continue;
        }
        if(s[0] == '0'){
            for(int i = 0 ; i <= p ; ++i){
                if(s[i] == '1'){
                    ve.pb(i);
                    flip(0,i-1,s);
                    break;
                }
            }
        }else{
            for(int i = 0 ; i <= p ; ++i){
                if(s[i] == '0'){
                    ve.pb(i);
                    flip(0,i-1,s);
                    break;
                }
                if(i == p){
                    ve.pb(i+1);
                    flip(0,p,s);
                }
            }
        }
    }//101 000 111 001 101
//    seen(s);
    if(x[n-1] == '1') ve.pb(n);
    for(int i = n - 2 ; i >= 0 ; --i){
        if(x[i] != x[i+1]) ve.pb(i+1);
    }
    cout<<ve.size()<<' ';
    for(auto i : ve){
        cout<<i<<' ';
    }
}
int main(){
//ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>Q;
    while(Q--){
        solve();
        cout<<'\n';
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define see(x) cout<< #x <<" = "<< x <<' ';
#define seen(x) cout<< #x <<" = "<< x <<'\n';
#define UWU cout<<'\n';
ll Q;
void flip(int L,int R,string &s){
    string z = s.substr(L,R-L+1);
    for(int i = 0 ; i < z.size() ; ++i){
        (z[i] == '1' ? z[i] = '0' : z[i] = '1');
    }
    int j = 0;
    reverse(z.begin(),z.end());
    for(int i = L ; i <= R ; ++i){
        s[i] = z[j];
        j++;
    }
}
void solve(){
    int n;cin>>n;
    string s,x;cin>>s>>x;
    vector<int> ve;
    //transform to full zero
    for(int i = 0 ; i < n - 1 ; ++i){
        if(s[i] != s[i+1]) ve.pb(i+1);
    }
    if(s[n-1] == '1') ve.pb(n);
    if(x[n-1] == '1') ve.pb(n);
    for(int i = n - 2 ; i >= 0 ; --i){
        if(x[i] != x[i+1]) ve.pb(i+1);
    }
    cout<<ve.size()<<' ';
    for(auto i : ve){
        cout<<i<<' ';
    }
}
int main(){
//ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>Q;
    while(Q--){
        solve();
        cout<<'\n';
    }
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
using namespace std;

const int maxn = 1003;

int main() {
	int t, n;
	string a, b;
	vector<int> ans;
	cin >> t;
	while (t--) {
		ans.clear();
		cin >> n;
		cin >> a >> b;
		for (int i = n - 1; i >= 0; i--) {
			if (a[0] != b[i]) {
				for (int j = 0; j <= i; j++)
					a[j] = (a[j] == '0'?'1':'0');
				reverse(a.begin(), a.begin() + i + 1);
				ans.push_back(i + 1);
			} else {
				a[0] = (a[0] == '0'?'1':'0');
				ans.push_back(1);
				for (int j = 0; j <= i; j++)
					a[j] = (a[j] == '0'?'1':'0');
				reverse(a.begin(), a.begin() + i + 1);
				ans.push_back(i + 1);
			}
		}
		int size = ans.size();
		cout<< size << " ";
		for (int i = 0; i < size; i++) {
			cout << ans[i] << " ";
		}cout << endl;
	}
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);//输入加速
	cout.tie(0);//输出加速
	int t, n;
	string a, b, a1;
	vector<int> ans;
	cin >> t;
	while (t--) {
		ans.clear();
		cin >> n;
		cin >> a >> b;
		int k = 1;
		int add = 1;
		int dec = n - 1;
		for (int i = n - 1; i >= 0; i--) {
			if (a[0] != b[i]) {
				ans.push_back(i + 1);
			} else {
				ans.push_back(1);
				ans.push_back(i + 1);
			}
			if (k % 2 == 1) {
				a[0] = (a[dec] == '0'?'1':'0');
				dec--;
			} else {
				a[0] = a[add];
//				if (i == 3) cout << "a[1] =" << a[1] << endl;
				add++;
			}
//			cout << "a[0] = " << a[0] << endl;
			k++;
			//a[0] = (a[i] == '0'?'1':'0');
//			if (dec++ % 2 == 1){
//				a[i - 1] = (a1[k++] == '0'?'1':'0');
//				cout << "a[0] = " << a[0] << endl;
//				cout << "a["  << i - 1  << "] = " << a[i - 1] << endl;
//			}
//			else {
//				a[i - 1] = a1[i];
//				cout << "a[0] = " << a[0] << endl;
//				cout << "a["  << i - 1  << "] = " << a[i - 1] << endl;
//			}
		}
		int size = ans.size();
		cout<< size << " ";
		for (int i = 0; i < size; i++) {
			cout << ans[i] << " ";
		}cout << endl;
	}
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);
	int t, n;
	string a, b;
	vector<int> ans;
	cin >> t;
	while (t--) {
		ans.clear();
		cin >> n;
		cin >> a >> b;
		for (int i = n - 1; i >= 0; i--) {
			if (a[0] != b[i]) {
				ans.push_back(i + 1);
			} else {
				ans.push_back(1);
				ans.push_back(i + 1);
			}
			int k = 1;
			if (i <= 1) continue;
			a[0] = (a[i] == '0'?'1':'0');
			if ((n - i) % 2 == 0)
				a[i - 1] = (a[k++] == '0'?'1':'0');
			else {
				a[i - 1] = a[i];
			}
		}
		int size = ans.size();
		cout<< size << " ";
		for (int i = 0; i < size; i++) {
			cout << ans[i] << " ";
		}cout << endl;
	}
	return 0;
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);//输入加速
	cout.tie(0);//输出加速
	int t, n;
	string a, b;
	vector<int> ans;
	cin >> t;
	while (t--) {
		ans.clear();
		cin >> n;
		cin >> a >> b;
		for (int i = n - 1; i >= 0; i--) {
			if (a[0] != b[i]) {
				ans.push_back(i + 1);
			} else {
				ans.push_back(1);
				ans.push_back(i + 1);
			}
			int k = 1;
			if (i <= 1) continue;
			a[0] = (a[i] == '0'?'1':'0');
			if ((n - i) % 2 == 0)
				a[i - 1] = (a[k++] == '0'?'1':'0');
			else {
				a[i - 1] = a[i];
			}
		}
		int size = ans.size();
		cout<< size << " ";
		for (int i = 0; i < size; i++) {
			cout << ans[i] << " ";
		}cout << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define ull unsigned long long
#define PI acos(-1)
#define pb(x)   push_back(x)
#define il inline
#define re register
#define IO; ios::sync_with_stdio(0);cin.tie(0);
#define ls (o<<1)
#define rs (o<<1|1)
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5+5;
const int maxm = 1e5+5;
const int INF = 0x3f3f3f3f;
const ll LINF = 3e17+1;
const int mod = 1e9+7;
int n, r,h;
inline int read(){
    register int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return (f==1)?x:-x;
}
char a[maxn],b[maxn];
int main()
{
    IO;
    int _;cin >> _;
    while (_--)
    {
        cin >> n;
        cin >> a + 1 >> b + 1;
        int rev = 0;
        int pp = 1, p = n;
        vector<int>ans;
        for (p = n; p >= 1; p--)
        {
            if ('0'+('0'- a[pp]+rev)%2 == b[p])
            {
                ans.pb(1);
                ans.pb(p);
            }
            else
            {
                ans.pb(p);
            }
            if (pp <= n/2)
            {
                pp = n - pp + 1;
            }
            else
                pp = n - pp + 2;
            rev++;
        }
        cout << ans.size();
        for (auto in : ans)
        {
            cout << " " << in;
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define ull unsigned long long
#define PI acos(-1)
#define pb(x)   push_back(x)
#define il inline
#define re register
#define IO; ios::sync_with_stdio(0);cin.tie(0);
#define ls (o<<1)
#define rs (o<<1|1)
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5+5;
const int maxm = 1e5+5;
const int INF = 0x3f3f3f3f;
const ll LINF = 3e17+1;
const int mod = 1e9+7;
int n, r,h;
inline int read(){
    register int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return (f==1)?x:-x;
}
char a[maxn],b[maxn];
int main()
{
    IO;
    int _;cin >> _;
    while (_--)
    {
        cin >> n;
        cin >> a + 1 >> b + 1;
        bool rev = 0;
        int l = 1, r = n, p = n;
        vector<int> ans;
        while (p >= 1)
        {
            if (!rev)
            {
                if (a[r] == b[p])
                {
                    r--, p--;
                    continue ;
                }
                else
                {
                    if (a[l] == b[p])
                    {
                        ans.pb(l);
                        ans.pb(p);
                        l++;
                        p--;
                    }
                    else
                    {
                        ans.pb(p);
                        p--;
                        l++;
                    }
                    rev = 1;
                }
            }
            else
            {
                if (a[l] == a[p])
                {
                    l++, p--;
                    continue ;
                }
                else
                {
                    if (a[r] == b[p])
                    {
                        ans.pb(r);
                        ans.pb(p);
                        r--;
                        p--;
                    }
                    else
                    {
                        ans.pb(p);
                        p--;
                        r--;
                    }
                    rev = 0;
                }
            }
        }
        cout << ans.size();
        for (auto in : ans)
        {
            cout << " " << in;
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define ull unsigned long long
#define PI acos(-1)
#define pb(x)   push_back(x)
#define il inline
#define re register
#define IO; ios::sync_with_stdio(0);cin.tie(0);
#define ls (o<<1)
#define rs (o<<1|1)
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5+5;
const int maxm = 1e5+5;
const int INF = 0x3f3f3f3f;
const ll LINF = 3e17+1;
const int mod = 1e9+7;
int n, r,h;
inline int read(){
    register int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return (f==1)?x:-x;
}
char a[maxn],b[maxn];
int main()
{
    IO;
    int _;cin >> _;
    while (_--)
    {
        cin >> n;
        cin >> a + 1 >> b + 1;
        int rev = 0;
        int pp = 1, p = n;
        vector<int>ans;
        for (p = n; p >= 1; p--)
        {
            if ('0'+( a[pp] - '0' +rev)%2 == b[p])
                ans.pb(1);
            ans.pb(p);
            if (pp <= n/2)
            {
                pp = n - pp + 1;
            }
            else
                pp = n - pp + 2;
            rev++;
        }
        cout << ans.size();
        for (auto in : ans)
        {
            cout << " " << in;
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define ull unsigned long long
#define PI acos(-1)
#define pb(x)   push_back(x)
#define il inline
#define re register
#define IO; ios::sync_with_stdio(0);cin.tie(0);
#define ls (o<<1)
#define rs (o<<1|1)
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5+5;
const int maxm = 1e5+5;
const int INF = 0x3f3f3f3f;
const ll LINF = 3e17+1;
const int mod = 1e9+7;
int n, r,h;
inline int read(){
    register int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return (f==1)?x:-x;
}
char a[maxn],b[maxn];
int main()
{
    IO;
    int _;cin >> _;
    while (_--)
    {
        cin >> n;
        cin >> a + 1 >> b + 1;
        int rev = 0;
        int pp = 1, p = n;
        vector<int>ans;
        for (p = n; p >= 1; p--)
        {
            if ('0'+('0'-a[pp]+rev%2) == b[p])
            {
                ans.pb(1);
                ans.pb(p);
            }
            else
            {
                ans.pb(p);
            }
            if (pp <= n/2)
            {
                pp = n - pp + 1;
            }
            else
                pp = n - pp + 2;
            rev++;
        }
        cout << ans.size();
        for (auto in : ans)
        {
            cout << " " << in;
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define ull unsigned long long
#define PI acos(-1)
#define pb(x)   push_back(x)
#define il inline
#define re register
#define IO; ios::sync_with_stdio(0);cin.tie(0);
#define ls (o<<1)
#define rs (o<<1|1)
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5+5;
const int maxm = 1e5+5;
const int INF = 0x3f3f3f3f;
const ll LINF = 3e17+1;
const int mod = 1e9+7;
int n, r,h;
inline int read(){
    register int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return (f==1)?x:-x;
}
int a[maxn];
int main()
{
    IO;
    int T;
    cin >> T;
    int m;
    char s1[maxn], s2[maxn];
    while (T--)
    {
        bool rev = 0;
        vector<int>ans;
        cin >> n;
        cin >> s1+1 >> s2+1;
        int l = 1, r = n;
        for (int pos = n; pos >= 1;)
        {
            if (!rev)
            {
                if (s1[r] == s2[pos])
                {
                    --r,--pos;
                    continue ;
                }
                if (s1[l] == s2[pos])
                {
                    ans.pb(1);
                    s1[l] = (s1[l]=='1'?'0':'1');
                }
                else
                {
                    ans.pb(pos);
                    --pos;
                    l++;
                    rev = 1;
                }
            }
            else
            {
                if (s1[l] != s2[pos])
                {
                    l++;
                    pos--;
                    continue ;
                }
                if (s1[r] != s2[pos])
                {
                    ans.pb(1);
                    s1[r] = (s1[r]=='1'?'0':'1');
                }
                else
                {
                    ans.pb(pos);
                    pos--;
                    r--;
                    rev = 0;
                }
            }
        }
        cout << ans.size();
        for (auto in : ans)
        {
            cout << " " << in;
        }
        cout << endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) if(debug) {cout << #x << ": " << x << endl;}
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

bool debug = false;
vi moves;

void operate(string &str, int length){
    reverse(str.begin(), str.begin() + length);
    for (int i = 0; i < length; i++)
    {
        str[i] = (str[i]=='0')?'1':'0';
    }
    moves.push_back(length);
}

void pull(int &idx, string strA, string strB){
    while (idx>=0 && strA[idx] == strB[idx]) idx--;
}

int main(){
    int n, t, idx;
    cin >> t;
    while (t--){
        cin >> n;
        string strA, strB;
        cin >> strA >> strB;
        idx = n-1;
        moves.clear();

        while (true){
            pull(idx, strA, strB);
            DEBUG(idx)
            DEBUG(strA)
            DEBUG(strB)
            if (idx <= 0) break;
            if (strB[idx] == strA[0]){
                operate(strA, 1);
                operate(strA, idx+1);
            } else {
                operate(strA, idx+1);
            }
        }
        if (strB[0] != strA[0]){
            moves.push_back(1);
        }
        cout << moves.size();
        for (int i : moves)
        {
            cout << ' ' << i;
        } cout << endl;

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) if(debug) {cout << #x << ": " << x << endl;}
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

bool debug = false;
vi moves;
bool isInverse = false;
int idxA, idxB, boundA;
string strA;

void move(){
    if (isInverse){
        idxA++;
    } else {
        idxA--;
    }
}

void operate(int length){
    swap(boundA, idxA);
    isInverse = !isInverse;
    moves.push_back(length);
}
char getChar (int idxA){
    return (isInverse)?((strA[idxA]=='1')?'0':'1'):strA[idxA];
}

void pull(string strA, string strB){
    DEBUG("pull")
    while (idxB>=0 && getChar(idxA) == strB[idxB]) {
        DEBUG(idxA)
        DEBUG(getChar(idxA))
        DEBUG(idxB)
        DEBUG(strB[idxB])
        move(); idxB--;
    };
    DEBUG("done")
}

int main(){
    int n, t;
    cin >> t;
    while (t--){
        cin >> n;
        string strB;
        cin >> strA >> strB;
        boundA = 0;
        idxA = idxB = n-1;
        moves.clear();

        while (true){
            pull(strA, strB);
            DEBUG(isInverse)
            DEBUG(boundA)
            DEBUG(idxA)
            DEBUG(idxB)
            DEBUG(strA)

            if (idxB <= 0) break;
            if (strB[idxB] == getChar(boundA)){
                DEBUG("Case 1")
                moves.push_back(1);
                strA[boundA] = (strA[boundA]=='0')?'1':'0';
                operate(idxB+1);
            } else {
                DEBUG("Case 2")
                operate(idxB+1);
            }
        }
        if (strB[0] != getChar(boundA)){
            moves.push_back(1);
        }
        cout << moves.size();
        for (int i : moves)
        {
            cout << ' ' << i;
        } cout << endl;

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) if(debug) {cout << #x << ": " << x << endl;}
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

bool debug = false;
vi moves;
bool isInverse;
int idxA, idxB, boundA;
string strA;

void move(){
    if (isInverse){
        idxA++;
    } else {
        idxA--;
    }
}

void operate(int length){
    swap(boundA, idxA);
    isInverse = !isInverse;
    moves.push_back(length);
}
char getChar (int idxA){
    return (isInverse)?((strA[idxA]=='1')?'0':'1'):strA[idxA];
}

void pull(string strA, string strB){
    DEBUG("pull")
    while (idxB>=0 && getChar(idxA) == strB[idxB]) {
        DEBUG(idxA)
        DEBUG(getChar(idxA))
        DEBUG(idxB)
        DEBUG(strB[idxB])
        move(); idxB--;
    };
    DEBUG("done")
}

int main(){
    int n, t;
    cin >> t;
    while (t--){
        cin >> n;
        string strB;
        cin >> strA >> strB;
        boundA = 0;
        idxA = idxB = n-1;
        isInverse = false;
        moves.clear();

        while (true){
            pull(strA, strB);
            DEBUG(isInverse)
            DEBUG(boundA)
            DEBUG(idxA)
            DEBUG(idxB)
            DEBUG(strA)

            if (idxB <= 0) break;
            if (strB[idxB] == getChar(boundA)){
                DEBUG("Case 1")
                moves.push_back(1);
                strA[boundA] = (strA[boundA]=='0')?'1':'0';
                operate(idxB+1);
            } else {
                DEBUG("Case 2")
                operate(idxB+1);
            }
        }
        if (strB[0] != getChar(boundA)){
            moves.push_back(1);
        }
        cout << moves.size();
        for (int i : moves)
        {
            cout << ' ' << i;
        } cout << endl;

    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) if(debug) {cout << #x << ": " << x << endl;}
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

bool debug = false;
vi moves;
bool isInverse;
int idxA, idxB, boundA;
vector<bool> strA, strB;

void move(){
    if (isInverse){
        idxA++;
    } else {
        idxA--;
    }
}

void operate(int length){
    swap(boundA, idxA);
    isInverse = !isInverse;
    moves.push_back(length);
}
bool getChar (int idxA){
    return (isInverse)?(!strA[idxA]):strA[idxA];
}

void pull(vector<bool> strA, vector<bool> strB){
    DEBUG("pull")
    while (idxB>=0 && getChar(idxA) == strB[idxB]) {
        DEBUG(idxA)
        DEBUG(getChar(idxA))
        DEBUG(idxB)
        DEBUG(strB[idxB])
        move(); idxB--;
    };
    DEBUG("done")
}

int main(){
    int n, t;
    cin >> t;
    while (t--){
        cin >> n;
        string stra, strb;
        cin >> stra >> strb;
        boundA = 0;
        idxA = idxB = n-1;
        isInverse = false;
        moves.clear();
        strA.resize(stra.length());
        strB.resize(strb.length());
        for (int i = 0; i<stra.length(); i++){
            strA[i] = (stra[i]=='1');
            strB[i] = (strb[i]=='1');
        }

        while (true){
            pull(strA, strB);

            if (idxB <= 0) break;
            if (strB[idxB] == getChar(boundA)){
                DEBUG("Case 1")
                moves.push_back(1);
                strA[boundA] = !strA[boundA];
                operate(idxB+1);
            } else {
                DEBUG("Case 2")
                operate(idxB+1);
            }
        }
        if (strB[0] != getChar(boundA)){
            moves.push_back(1);
        }
        cout << moves.size();
        for (int i : moves)
        {
            cout << ' ' << i;
        } cout << endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int uint;
#define rint register int
#define pb push_back
#define mkp(x,y) make_pair(x,y)
#define db double
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2) EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
inline int rd() {
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return x*f;
}
const int N=100010;
char a[N],b[N];
int n;
vector<int>ans;
signed main() {
	int T=rd();
	while(T--) {
		n=rd();ans.clear();
		scanf("%s%s",a+1,b+1);
		for(int i=n;i>=1;--i) {
			if(a[i]!=b[i]) {
				if(b[i]==a[1])ans.pb(1);
				ans.pb(i);
			}
		}
		printf("%d",(int)ans.size());for(uint i=0;i<ans.size();++i)printf(" %d",ans[i]);
		puts("");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int uint;
#define rint register int
#define pb push_back
#define mkp(x,y) make_pair(x,y)
#define db double
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2) EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
inline int rd() {
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return x*f;
}
const int N=100010;
char a[N],b[N];
int n;
vector<int>ans;
signed main() {
	int T=rd();
	while(T--) {
		n=rd();ans.clear();
		scanf("%s%s",a+1,b+1);
		for(int i=n,j=1;i>=1;--i,++j) {
			if(j&1) {
				if(b[i]==a[(j+1)>>1])ans.pb(1);
			} else if(b[i]!=a[n+1-(j>>1)])ans.pb(1);
			ans.pb(i);
		}
		printf("%d",(int)ans.size());for(uint i=0;i<ans.size();++i)printf(" %d",ans[i]);
		puts("");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int uint;
#define rint register int
#define pb push_back
#define mkp(x,y) make_pair(x,y)
#define db double
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2) EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
inline int rd() {
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return x*f;
}
const int N=100010;
char a[N],b[N];
int n;
vector<int>ans;
signed main() {
	int T=rd();
	while(T--) {
		n=rd();ans.clear();
		scanf("%s%s",a+1,b+1);
		for(int i=n;i>=1;--i) {
			if((n-i+1)&1) {
				if(b[i]==a[(i+1)>>1])ans.pb(1);
			} else if(b[i]==a[n+1-(i>>1)])ans.pb(1);
			ans.pb(i);
		}
		printf("%d",(int)ans.size());for(uint i=0;i<ans.size();++i)printf(" %d",ans[i]);
		puts("");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int uint;
#define rint register int
#define pb push_back
#define mkp(x,y) make_pair(x,y)
#define db double
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2) EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
inline int rd() {
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return x*f;
}
const int N=100010;
char a[N],b[N];
int n;
vector<int>ans;
signed main() {
	int T=rd();
	while(T--) {
		n=rd();ans.clear();int num=0;
		scanf("%s%s",a+1,b+1);
		for(int i=n;i>=1;--i) {
			if(num&1) {
				if(b[i]==a[(i+1)>>1])ans.pb(1);
			} else if(b[i]==a[n+1-(i>>1)])ans.pb(1);
			ans.pb(i);++num;
		}
		printf("%d",(int)ans.size());for(uint i=0;i<ans.size();++i)printf(" %d",ans[i]);
		puts("");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned int uint;
#define rint register int
#define pb push_back
#define mkp(x,y) make_pair(x,y)
#define db double
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2) EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
inline int rd() {
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return x*f;
}
const int N=100010;
char a[N],b[N];
int n;
vector<int>ans;
signed main() {
	int T=rd();
	while(T--) {
		n=rd();ans.clear();
		scanf("%s%s",a+1,b+1);
		for(int i=n;i>=1;--i) {
			if(i&1) {
				if(b[i]==a[(i+1)>>1])ans.pb(1);
			} else if(b[i]==a[n+1-(i>>1)])ans.pb(1);
			ans.pb(i);
		}
		printf("%d",(int)ans.size());for(uint i=0;i<ans.size();++i)printf(" %d",ans[i]);
		puts("");
	}
	return 0;
}


#include <bits/stdc++.h>

#define lli long long int

using namespace std;

int T, n;
string a, b;
vector<int> ans;

void sw(int x) {
    if (a[x] == '1') a[x] = '0';
    else a[x] = '1';
}

int main() {
    ios::sync_with_stdio(0);

//    freopen("file.in", "r", stdin);
//    freopen("file.out", "w", stdout);

    cin >> T;

    for (int t = 0; t < T; t++) {
        cin >> n >> a >> b;
        ans.clear();
        for (int i = n - 1; i > 0; i--) {
            if (a[0] == b[i]) {
                sw(0);
                ans.push_back(1);
            }
            if ((n - 1 - i) % 2 != 0) sw(i);
            swap(a[i], a[0]);
            sw(0);
            ans.push_back(i + 1);
        }
        if (a[0] != b[0]) ans.push_back(1);
        cout << ans.size() << " ";
        for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define lli long long int

using namespace std;

int T, n, cnt, ind;
string a, b;
vector<int> ans;

void sw(int x) {
    if (a[x] == '1') a[x] = '0';
    else a[x] = '1';
}

int main() {
    ios::sync_with_stdio(0);

//    freopen("file.in", "r", stdin);
//    freopen("file.out", "w", stdout);

    cin >> T;

    for (int t = 0; t < T; t++) {
        cin >> n >> a >> b;
        ans.clear();
        cnt = 0;
        ind = n - 1;
        for (int i = n - 1; i > 0; i--) {
            if (cnt % 2 == 0) {
                ind = i;
            } else {
                ind = 1;
                sw(ind);
            }
            if (a[ind] == b[i]) {
                if (cnt%2 == 0) ind--;
                else ind++;
                continue;
            }
            if (a[0] == b[i]) {
                sw(0);
                ans.push_back(1);
            }
            sw(0);
            ans.push_back(i + 1);
            cnt++;
        }
        if (a[0] != b[0]) ans.push_back(1);
        cout << ans.size() << " ";
        for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define lli long long int

using namespace std;

int T, n;
string a, b;
vector<int> ans;

void sw(int x) {
    if (a[x] == '1') a[x] = '0';
    else a[x] = '1';
}

int main() {
    ios::sync_with_stdio(0);

//    freopen("file.in", "r", stdin);
//    freopen("file.out", "w", stdout);

    cin >> T;

    for (int t = 0; t < T; t++) {
        cin >> n >> a >> b;
        ans.clear();
        for (int i = n - 1; i > 0; i--) {
            if (a[0] == b[i]) {
                sw(0);
                ans.push_back(1);
            }
            swap(a[i], a[0]);
            sw(0);
            ans.push_back(i + 1);
        }
        if (a[0] != b[0]) ans.push_back(1);
        cout << ans.size() << " ";
        for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define lli long long int

using namespace std;

int T, n, l, r, ind;
string a, b;
vector<int> ans;

void sw(int x) {
    if (a[x] == '1') a[x] = '0';
    else a[x] = '1';
}

int main() {
    ios::sync_with_stdio(0);

//    freopen("file.in", "r", stdin);
//    freopen("file.out", "w", stdout);

    cin >> T;

    for (int t = 0; t < T; t++) {
        cin >> n >> a >> b;
        ans.clear();
        l = 1;
        r = n - 1;
        for (int i = n - 1; i > 0; i--) {
            if (a[0] == b[i]) {
                sw(0);
                ans.push_back(1);
            }
            if ((n - 1 - i) % 2 == 0) {
                ind = r--;
                sw(ind);
            } else ind = l++;
            ans.push_back(i + 1);
            swap(a[ind], a[0]);
        }
        if (a[0] != b[0]) ans.push_back(1);
        cout << ans.size() << " ";
        for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define lli long long int

using namespace std;

int T, n, cnt, ind;
string a, b;
vector<int> ans;

void sw(int x) {
    if (a[x] == '1') a[x] = '0';
    else a[x] = '1';
}

int main() {
    ios::sync_with_stdio(0);

//    freopen("file.in", "r", stdin);
//    freopen("file.out", "w", stdout);

    cin >> T;

    for (int t = 0; t < T; t++) {
        cin >> n >> a >> b;
        ans.clear();
        cnt = 0;
        ind = n - 1;
        for (int i = n - 1; i > 0; i--) {
            if (cnt % 2 == 0) ind = i;
            else {
                ind = 1;
                sw(ind);
            }
            if (a[0] == b[i]) {
                sw(0);
                ans.push_back(1);
            }
            sw(0);
            ans.push_back(i + 1);
            cnt++;
        }
        if (a[0] != b[0]) ans.push_back(1);
        cout << ans.size() << " ";
        for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define INF (int)0x3f3f3f3f
#define LINF (long long)0x3f3f3f3f3f3f3f3fll
#define mp make_pair
#define pb push_back

typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t; cin >> t;

	while (t--){
		int n; cin >> n;
		string a, b;
		string str;
		cin >> str;
		a += str;
		cin >> str;
		b += str;
		a += '0'; b += '0';
		int count = 0;
		vector <int> ans1, ans2;
		for (int i = 1; i < n+1; i++)
			if (a[i-1] != a[i])
				ans1.pb(i);
		for (int i = 1; i < n+1; i++)
			if (b[i-1] != b[i])
				ans2.pb(i);
		cout << ans1.size() + ans2.size();
		for (auto k : ans1)
			cout << " " << k;
		reverse(ans2.begin(), ans2.end());
		for (auto k : ans2)
			cout << " " << k;
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define INF (int)0x3f3f3f3f
#define LINF (long long)0x3f3f3f3f3f3f3f3fll
#define mp make_pair
#define pb push_back

typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t; cin >> t;

	while (t--){
		int n; cin >> n;
		string a = "0", b = "0";
		string str;
		cin >> str;
		a += str;
		cin >> str;
		b += str;
		int count = 0;
		vector <int> ans1, ans2;
		for (int i = 1; i < n+1; i++)
			if (a[i-1] != a[i]) ans1.pb(i);
		for (int i = 1; i < n+1; i++)
			if (b[i-1] != b[i]) ans2.pb(i);
		cout << ans1.size() + ans2.size();
		for (auto k : ans1)
			cout << " " << k;
		reverse(ans2.begin(), ans2.end());
		for (auto k : ans2)
			cout << " " << k;
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define INF (int)0x3f3f3f3f
#define LINF (long long)0x3f3f3f3f3f3f3f3fll
#define mp make_pair
#define pb push_back

typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t; cin >> t;

	while (t--){
		int n; cin >> n;
		string a = "0", b = "0";
		string str;
		cin >> str; a += str;
		cin >> str; b += str;
		int count = 0;
		vector <int> ans1, ans2;
		for (int i = 0; i < n; i++)
			if (a[i-1] != a[i]) ans1.pb(i);
		for (int i = 0; i < n; i++)
			if (b[i-1] != b[i]) ans2.pb(i);
		cout << ans1.size() + ans2.size();
		for (auto k : ans1)
			cout << " " << k+1;
		reverse(ans2.begin(), ans2.end());
		for (auto k : ans2)
			cout << " " << k+1;
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define INF (int)0x3f3f3f3f
#define LINF (long long)0x3f3f3f3f3f3f3f3fll
#define mp make_pair
#define pb push_back

typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t; cin >> t;

	while (t--){
		int n; cin >> n;
		string a = "0", b = "0";
		string str;
		cin >> str;
		a += str;
		cin >> str;
		b += str;
		int count = 0;
		vector <int> ans1, ans2;
		for (int i = 1; i < n+1; i++)
			if (a[i-1] != a[i]) ans1.pb(i);
		for (int i = 1; i < n+1; i++)
			if (b[i-1] != b[i]) ans2.pb(i);
		cout << ans1.size() + ans2.size();
		for (auto k : ans1)
			cout << " " << k;
		//reverse(ans2.begin(), ans2.end());
		for (auto k : ans2)
			cout << " " << k;
		cout << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef pair<int, int> pp;
typedef long long int ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
// online submission
#endif
    int test;
    cin>>test;
    while(test--){
        string c,d;
        int n;
        cin>>n>>c>>d;
        vector<char> a(n);
        vector<char> b(n);
        for(int i=0;i<n;i++){
        	a[i]=c[i];
        	b[i]=d[i];
        }
        vector<int> len;
        while(n>0){
            while(a[n-1]==b[n-1]){
                a.pop_back();
                b.pop_back();
                n--;
            }
            if(n<=0){
            	break;
            }
            int first=-1,second=-1;
            for(int i=0;i<n;i++){
            	if(a[i]!=b[n-i-1]&& (first!=-1)){
            		break;
            	}
            	else if(a[i]==b[n-i-1]){
            		if(first==-1){
            			first=i;
            			second=i;
            		}
            		else if(first!=-1){
            			second=i;
            		}
            		if(a[i]=='0'){
            			a[i]='1';
            		}
            		else{
            			a[i]='0';
            		}
            	}
            }
            if(first!=-1){
            	len.push_back(second-first+1);
            }
            len.push_back(n);
            vector<char> temp;
                for(int i=n-1;i>=0;i--){
                    temp.push_back(a[i]);
                }
                for(int i=0;i<n;i++){
                    if(temp[i]=='1'){
                        a[i]='0';
                    }
                    else{
                        a[i]='1';
                    }
            }

        }
        cout<<len.size()<<" ";
       	for(int i=0;i<len.size();i++){
       		cout<<len[i]<<" ";
       	}
       	cout<<"\n";

    }
}


#include <bits/stdc++.h>
/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef pair<int, int> pp;
typedef long long int ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
// online submission
#endif
    int test;
    cin >> test;
    while (test--) {
        string c, d;
        int n;
        cin >> n >> c >> d;
        vector<char> a(n);
        vector<char> b(n);
        if(c==d){
            cout<<0<<"\n";
            continue;
        }
        for (int i = 0; i < n; i++) {
            a[i] = c[i];
            b[i] = d[i];
        }
        vector<int> len;
        while (n > 0) {
            while (a[n - 1] == b[n - 1]) {
                a.pop_back();
                b.pop_back();
                n--;
            }
            if (n <= 0) {
                break;
            }
            int count = 0, upg = 0;
            while ( upg < n && a[upg] != b[n - upg - 1]) {
                upg++;
            }
            while (upg<n && a[upg]==b[n-upg-1]){
                if(a[upg]=='0'){
                    a[upg]='1';
                }
                else{
                    a[upg]='0';
                }
                count++;
            }
            len.push_back(count);
            len.push_back(n);
            vector<char> temp;
            for (int i = n - 1; i >= 0; i--) {
                temp.push_back(a[i]);
            }
            for (int i = 0; i < n; i++) {
                if (temp[i] == '1') {
                    a[i] = '0';
                }
                else {
                    a[i] = '1';
                }
            }

        }
        cout << len.size() << " ";
        for (int i : len) cout << i << " ";
        cout << "\n";

    }
}


#include <bits/stdc++.h>
/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef pair<int, int> pp;
typedef long long int ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
// online submission
#endif
    int test;
    cin>>test;
    while(test--){
        string c,d;
        int n;
        cin>>n>>c>>d;
        vector<char> a(n);
        vector<char> b(n);
        for(int i=0;i<n;i++){
        	a[i]=c[i];
        	b[i]=d[i];
        }
        vector<int> len;
        while(n>0){
            while(a[n-1]==b[n-1]){
                a.pop_back();
                b.pop_back();
                n--;
            }
            if(n<=0){
            	break;
            }
            if(a[0]==b[n-1]){
            	len.push_back(1);
            	if(b[n-1]=='1'){
            		a[0]='0';
            	}
    			else{
    				a[0]='1';
    			}
            }
            len.push_back(n);
            vector<char> temp;
                for(int i=n-1;i>=0;i--){
                    temp.push_back(a[i]);
                }
                for(int i=0;i<n;i++){
                    if(temp[i]=='1'){
                        a[i]='0';
                    }
                    else{
                        a[i]='1';
                    }
            }

        }
        cout<<len.size()<<" ";
       	for(int i=0;i<len.size();i++){
       		cout<<len[i]<<" ";
       	}
       	cout<<"\n";

    }
}


#include <bits/stdc++.h>
/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef pair<int, int> pp;
typedef long long int ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
// online submission
#endif
    int test;
    cin>>test;
    while(test--){
        string c,d;
        int n;
        cin>>n>>c>>d;
        vector<char> a(n);
        vector<char> b(n);
        for(int i=0;i<n;i++){
        	a[i]=c[i];
        	b[i]=d[i];
        }
        vector<int> len;
        while(n>0){
            while(a[n-1]==b[n-1]){
                a.pop_back();
                b.pop_back();
                n--;
            }
            if(n<=0){
            	break;
            }
            int count=0,j=0;
            while(j<n && a[j]==b[n-j-1]){
            	if(b[n-1]=='1'){
            		a[0]='0';
            	}
    			else{
    				a[0]='1';
    			}
    			j++;
    			count++;
            }
           	if(count>0){
           		len.push_back(count);
           	}
            len.push_back(n);
            vector<char> temp;
                for(int i=n-1;i>=0;i--){
                    temp.push_back(a[i]);
                }
                for(int i=0;i<n;i++){
                    if(temp[i]=='1'){
                        a[i]='0';
                    }
                    else{
                        a[i]='1';
                    }
            }

        }
        cout<<len.size()<<" ";
       	for(int i=0;i<len.size();i++){
       		cout<<len[i]<<" ";
       	}
       	cout<<"\n";

    }
}


#include <bits/stdc++.h>
/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef pair<int, int> pp;
typedef long long int ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
// online submission
#endif
    int test;
    cin>>test;
    while(test--){
        string c,d;
        int n;
        cin>>n>>c>>d;
        vector<char> a(n);
        vector<char> b(n);
        for(int i=0;i<n;i++){
        	a[i]=c[i];
        	b[i]=d[i];
        }
        vector<int> len;
        while(n>0){
            while(a[n-1]==b[n-1]){
                a.pop_back();
                b.pop_back();
                n--;
            }
            if(n<=0){
            	break;
            }
            int count=0;
            for(int i=0;i<n;i++){
            	if(a[i]==b[n-i-1]){
            		if(a[i]=='0'){
            			a[i]='1';
            		}
            		else{
            			a[i]='0';
            		}
            		count++;
            	}
            	else{
            		break;
            	}
            }
           	if(count>0){
           		len.push_back(count);
           	}
            len.push_back(n);
            vector<char> temp;
                for(int i=n-1;i>=0;i--){
                    temp.push_back(a[i]);
                }
                for(int i=0;i<n;i++){
                    if(temp[i]=='1'){
                        a[i]='0';
                    }
                    else{
                        a[i]='1';
                    }
            }

        }
        cout<<len.size()<<" ";
       	for(int i=0;i<len.size();i++){
       		cout<<len[i]<<" ";
       	}
       	cout<<"\n";

    }
}


#include <bits/stdc++.h>
/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef pair<int, int> pp;
typedef long long int ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
// online submission
#endif
    int test;
    cin >> test;
    while (test--) {
        int n;
        cin>>n;
        string c,d;
        cin>>c>>d;
        vector<int> a(n),b(n);
        for(int i=0;i<n;i++){
            a[i]=c[i]-48;
            b[i]=d[i]-48;
        }
        std::vector<int> len;
        int first=0,last=n-1,blast=n-1,count=0;
        while(blast>=0&& n){
            if(count%2){
                while(blast>=0&&n&&(a[first]!=b[blast])){
                    blast--;
                    first++;
                    n--;
                }
                if(last<first||n<=0||blast<0){
                    break;
                }
                if(a[last]!=b[blast]){
                    a[last]=1-a[last];
                    len.push_back(1);
                }
                len.push_back(last-first+1);
                while(n&&blast>=0&&a[last]==b[blast]){
                    last--;
                    blast--;
                    n--;
                }
            }
            else{
                while(blast>=0&&n&&(a[last]==b[blast])){
                    blast--;
                    last--;
                    n--;
                }
                if(last<first||n<=0||blast<0){
                    break;
                }
                if(1-a[first]!=b[blast]){
                    a[first]=1-a[first];
                    len.push_back(1);
                }
                len.push_back(last-first+1);
                count++;
                while(n&&blast>=0&&a[first]!=b[blast]){
                    first++;
                    blast--;
                    n--;
                }
            }
        }
        cout<<len.size()<<" ";
        for(int i=0;i<len.size();i++){
            cout<<len[i]<<" ";
        }
        cout<<"\n";
    }

}


#include <bits/stdc++.h>
/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef pair<int, int> pp;
typedef long long int ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
// online submission
#endif
    int test;
    cin >> test;
    while (test--) {
        string c, d;
        int n;
        cin >> n >> c >> d;
        vector<char> a(n);
        vector<char> b(n);
        for (int i = 0; i < n; i++) {
            a[i] = c[i];
            b[i] = d[i];
        }
        vector<int> len;
        while (n > 0) {
            while (a[n - 1] == b[n - 1]) {
                a.pop_back();
                b.pop_back();
                n--;
            }
            if (n <= 0) {
                break;
            }
            int count = 0, upg = 0;
            while ( upg < n && a[upg] != b[n - upg - 1]) {
                upg++;
            }
            while (upg<n && a[upg]==b[n-upg-1]){
                if(a[upg]=='0'){
                    a[upg]='1';
                }
                else{
                    a[upg]='0';
                }
                count++;
            }
            len.push_back(count);
            len.push_back(n);
            vector<char> temp;
            for (int i = n - 1; i >= 0; i--) {
                temp.push_back(a[i]);
            }
            for (int i = 0; i < n; i++) {
                if (temp[i] == '1') {
                    a[i] = '0';
                }
                else {
                    a[i] = '1';
                }
            }

        }
        cout << len.size() << " ";
        for (int i : len) cout << i << " ";
        cout << "\n";

    }
}


#include <bits/stdc++.h>
/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef pair<int, int> pp;
typedef long long int ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
// online submission
#endif
    int test;
    cin >> test;
    while (test--) {
        int n;
        cin>>n;
        string c,d;
        cin>>c>>d;
        vector<int> a(n),b(n);
        for(int i=0;i<n;i++){
            a[i]=c[i]-48;
            b[i]=d[i]-48;
        }
        std::vector<int> len;
        int first=0,last=n-1,blast=n-1,count=0;
        while(blast>=0&& n){
            if(count%2){
                while(blast>=0&&n&&(a[first]!=b[blast])){
                    blast--;
                    first++;
                    n--;
                }
                if(last<first||n<=0||blast<0){
                    break;
                }
                if(a[last]!=b[blast]){
                    a[last]=1-a[last];
                    len.push_back(1);
                }
                count++;
                len.push_back(last-first+1);
                while(n&&blast>=0&&a[last]==b[blast]){
                    last--;
                    blast--;
                    n--;
                }
            }
            else{
                while(blast>=0&&n&&(a[last]==b[blast])){
                    blast--;
                    last--;
                    n--;
                }
                if(last<first||n<=0||blast<0){
                    break;
                }
                if(1-a[first]!=b[blast]){
                    a[first]=1-a[first];
                    len.push_back(1);
                }
                len.push_back(last-first+1);
                count++;
                while(n&&blast>=0&&a[first]!=b[blast]){
                    first++;
                    blast--;
                    n--;
                }
            }
        }
        cout<<len.size()<<" ";
        for(int i=0;i<len.size();i++){
            cout<<len[i]<<" ";
        }
        cout<<"\n";
    }

}


#include <bits/stdc++.h>
/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef pair<int, int> pp;
typedef long long int ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
// online submission
#endif
    int test;
    cin>>test;
    while(test--){
        string c,d;
        int n;
        cin>>n>>c>>d;
        vector<char> a(n);
        vector<char> b(n);
        for(int i=0;i<n;i++){
        	a[i]=c[i];
        	b[i]=d[i];
        }
        vector<int> len;
        while(n>0){
            while(a[n-1]==b[n-1]){
                a.pop_back();
                b.pop_back();
                n--;
            }
            if(n<=0){
            	break;
            }
            int count=0;
            for(int i=0;i<n;i++){
            	if(a[i]==b[n-i-1]){
            		if(a[i]=='0'){
            			a[i]='1';
            		}
            		else{
            			a[i]='0';
            		}
            		count++;
            	}
            }
           	if(count>0){
           		len.push_back(count);
           	}
            len.push_back(n);
            vector<char> temp;
                for(int i=n-1;i>=0;i--){
                    temp.push_back(a[i]);
                }
                for(int i=0;i<n;i++){
                    if(temp[i]=='1'){
                        a[i]='0';
                    }
                    else{
                        a[i]='1';
                    }
            }

        }
        cout<<len.size()<<" ";
       	for(int i=0;i<len.size();i++){
       		cout<<len[i]<<" ";
       	}
       	cout<<"\n";

    }
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stdlib.h>
#include<vector>
using namespace std;
const int N = 1e3 + 5;

string a,b;
int cnt;
vector<int> pos;

void solve(string &a,int p) {
	cnt++;
	for(int i = 0;i<=p/2;i++) {
		if(i == p-i) {
			if(a[i] == '0') a[i] = '1';
			else			a[i] = '0';
			break;
		}
		if(a[i] == a[p-i]) {
			if(a[i] == '0') a[i] = '1';
			else			a[i] = '0';
			if(a[p-i] == '0') a[p-i] = '1';
			else			  a[p-i] = '0';
		}
	}
	//cout<<a<<" "<<p<<endl;
}

int main() {
	//string a,b;
	int n,t;
	scanf("%d",&t);
	while(t--) {
		pos.clear();
		cnt = 0;
		a = b = "";
		scanf("%d",&n);
		cin>>a;
		cin>>b;
		int f = 0;
		while(a != b) {
			//cout<<a<<b<<endl;
			for(int i = n-1;i >= 0;i--) {
				if(a[i] == b[i] && i != 0) continue;
				if(a[i] == a[0]) {
					solve(a,i);
					pos.push_back(i+1);
					break;
				}
			}
		}
		cout<<cnt<<" ";
		for(int i = 0;i<pos.size();i++) {
			cout<<pos[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stdlib.h>
#include<vector>
using namespace std;
const int N = 1e5 + 5;

string a,b;
int cnt;
vector<int> pos;

void solve(string &a,int p) {
	cnt++;
	for(int i = 0;i<=p/2;i++) {
		if(i == p-i) {
			if(a[i] == '0') a[i] = '1';
			else			a[i] = '0';
			break;
		}
		if(a[i] == a[p-i]) {
			if(a[i] == '0') a[i] = '1';
			else			a[i] = '0';
			if(a[p-i] == '0') a[p-i] = '1';
			else			  a[p-i] = '0';
		}
	}
	//cout<<a<<" "<<p<<endl;
}

int main() {
	//string a,b;
	int n,t;
	scanf("%d",&t);
	while(t--) {
		pos.clear();
		cnt = 0;
		a.resize(N);
		b.resize(N);
		scanf("%d",&n);
		getchar();
		getline(cin,a);
		getline(cin,b);
		while(a != b) {
			//cout<<a<<b<<endl;
			for(int i = n-1;i >= 0;i--) {
				if(a[i] == b[i] && i != 0) continue;
				if(a[i] == a[0]) {
					solve(a,i);
					pos.push_back(i+1);
					break;
				}
			}
		}
		cout<<cnt<<" ";
		for(int i = 0;i<pos.size();i++) {
			cout<<pos[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stdlib.h>
#include<vector>
using namespace std;
const int N = 1e5 + 5;

string a,b;
int cnt;
vector<int> pos;

void solve(string &a,int p) {
	cnt++;
	for(int i = 0;i<=p/2;i++) {
		if(i == p-i) {
			if(a[i] == '0') a[i] = '1';
			else			a[i] = '0';
			break;
		}
		if(a[i] == a[p-i]) {
			if(a[i] == '0') a[i] = '1';
			else			a[i] = '0';
			if(a[p-i] == '0') a[p-i] = '1';
			else			  a[p-i] = '0';
		}
	}
	//cout<<a<<" "<<p<<endl;
}

int main() {
	//string a,b;
	int n,t;
	scanf("%d",&t);
	while(t--) {
		pos.clear();
		cnt = 0;
		a = b = "";
		scanf("%d",&n);
		getchar();
		getline(cin,a);
		getline(cin,b);
		//scanf("%s",&b[0]);
		int f = 0;
		//printf("%s\n",a.c_str());
		//printf("%s\n",b.c_str());
		while(a != b) {
			//cout<<a<<b<<endl;
			for(int i = n-1;i >= 0;i--) {
				if(a[i] == b[i] && i != 0) continue;
				if(a[i] == a[0]) {
					solve(a,i);
					pos.push_back(i+1);
					break;
				}
			}
		}
		cout<<cnt<<" ";
		for(int i = 0;i<pos.size();i++) {
			cout<<pos[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stdlib.h>
#include<vector>
using namespace std;
const int N = 1e5 + 5;

char a[N],b[N];
int cnt;
vector<int> pos;

void solve(char *a , int p) {
	cnt++;
	for(int i = 0;i<=p/2;i++) {
		if(i == p-i) {
			if(a[i] == '0') a[i] = '1';
			else			a[i] = '0';
			break;
		}
		if(a[i] == a[p-i]) {
			if(a[i] == '0') a[i] = '1';
			else			a[i] = '0';
			if(a[p-i] == '0') a[p-i] = '1';
			else			  a[p-i] = '0';
		}
	}
	//cout<<a<<" "<<p<<endl;
}

int main() {
	//string a,b;
	int n,t;
	scanf("%d",&t);
	while(t--) {
		pos.clear();
		cnt = 0;
		scanf("%d",&n);
		scanf("%s",a);
		scanf("%s",b);
		while(strcmp(a,b) != 0) {
			//cout<<a<<b<<endl;
			for(int i = n-1;i >= 0;i--) {
				if(a[i] == b[i] && i != 0) continue;
				if(a[i] == a[0]) {
					solve(a,i);
					pos.push_back(i+1);
					break;
				}
			}
		}
		cout<<cnt<<" ";
		for(int i = 0;i<pos.size();i++) {
			cout<<pos[i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stdlib.h>
#include<vector>
#include<string>
#include<cctype>
using namespace std;
const int N = 1e3;

int main() {
	int t, n;
	string a, b;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    while(t--) {
        cin >> n >> a >> b;
        vector<int> p1, p2;
        a += '0'; b += '0';
        for(int i = 1; i <= n; i++) {
            if(a[i] != a[i - 1]) p1.push_back(i);
            if(b[i] != b[i - 1]) p2.push_back(i);
        }
        p1.insert(p1.end(), p2.rbegin(), p2.rend());
        cout << p1.size();
        for(int i = 0;i<p1.size() ;i++) {
            cout <<' '<<p1[i] ;
        }
        cout << endl;
    }
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<map>
#define debug(x) cout<<#x<<":"<<x<<endl
using namespace std;

#define MP make_pair
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define inc(i,a,b) for(int i=a;i<(int)b;++i)
#define pb push_back
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define bye exit(0)
#define YES puts("YES")
#define NO  puts("NO")
#define FORV(t1) for(int t1=head[u];t1;t1=Next[t1])
#define MAX(x,y) x=max(x,y)
#define MIN(x,y) x=min(x,y)
#define CLR(a,val) memset(a,val,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int>pii;
void R() {}
template<class T> void _R(T &x) {cin>>x;}
void _R(signed &x) {scanf("%d", &x);}
void _R(LL &x) {scanf("%I64d", &x);}
void _R(double &x) {scanf("%lf",&x);}
void _R(char &x) {scanf(" %c",&x);}
void _R(char *x) {scanf("%s",x);}
template<class T, class... Tx> void R(T &head, Tx &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const signed &x) { printf("%d", x); }
void _W(const LL &x) { printf("%I64d", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const double EPS = 1e-7;
const int N=1e6+5;
//head
int t,n,a[100005],b[100005];
signed main(){
  int t;
  cin>>t;
  while(t--){
    scanf("%d",&n);
    rep(i,1,n) scanf("%1d",&a[i]);
    rep(i,1,n) scanf("%1d",&b[i]);
    vector<int>ans;
    int op=0,l=1,r=n+1;
    for(int i=n;i>=1;i--){
      int xx,pre,yy=b[i];
      if(op==0){
        r--;
      }
      if(op==1){
        r++;
      }

      xx=a[r]^op,pre=a[l]^op;

//      if(i==2){
//        cout<<l<<' '<<r<<endl;
//        cout<<op<<endl;
//        printf("xx=%d,pre=%d,yy=%d,\n",xx,pre,yy);
//      }
      if(xx==yy){
        continue;
      }
      if(i==1&&xx!=yy){
        ans.push_back(1);
        continue;
      }
      if(xx!=yy&&xx!=pre){
        ans.push_back(1);
        a[l]^=1;
        ans.push_back(i);
        swap(l,r);
        op^=1;
      }
      if(xx!=yy&&xx==pre){
        ans.push_back(i);
        swap(l,r);
        op^=1;
      }
    }
    if(ans.size()){
      printf("%d\n",ans.size());
      for(int i:ans) printf("%d ",i);puts("");
    }
    if(!ans.size()) puts("0");
  }
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<map>
#define debug(x) cout<<#x<<":"<<x<<endl
using namespace std;

#define MP make_pair
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define inc(i,a,b) for(int i=a;i<(int)b;++i)
#define pb push_back
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define bye exit(0)
#define YES puts("YES")
#define NO  puts("NO")
#define FORV(t1) for(int t1=head[u];t1;t1=Next[t1])
#define MAX(x,y) x=max(x,y)
#define MIN(x,y) x=min(x,y)
#define CLR(a,val) memset(a,val,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int>pii;
void R() {}
template<class T> void _R(T &x) {cin>>x;}
void _R(signed &x) {scanf("%d", &x);}
void _R(LL &x) {scanf("%I64d", &x);}
void _R(double &x) {scanf("%lf",&x);}
void _R(char &x) {scanf(" %c",&x);}
void _R(char *x) {scanf("%s",x);}
template<class T, class... Tx> void R(T &head, Tx &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const signed &x) { printf("%d", x); }
void _W(const LL &x) { printf("%I64d", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const double EPS = 1e-7;
const int N=1e6+5;
//head
int t,n,a[100005],b[100005];
signed main(){
  int t;
  cin>>t;
  while(t--){
    scanf("%d",&n);
    rep(i,1,n) scanf("%1d",&a[i]);
    rep(i,1,n) scanf("%1d",&b[i]);
    vector<int>ans;
    int op=0,l=1,r=n+1;
    for(int i=n;i>=1;i--){
      int xx,pre,yy=b[i];
      if(op==0){
        r--;
      }
      if(op==1){
        r++;
      }
      xx=a[r]^op,pre=a[l]^op;
      if(xx==b[i]){
        continue;
      }
      else{
        if(xx!=pre){
          ans.push_back(1);
          a[l]^=1;
          ans.push_back(i);
          swap(l,r);
          op^=1;
        }
        else if(xx!=pre){
          ans.push_back(i);
          swap(l,r);
          op^=1;
        }
      }
    }
    if(ans.size()){
      for(int i:ans) printf("%d ",i);puts("");
    }
    if(!ans.size()) puts("0");
  }
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<map>
#define debug(x) cout<<#x<<":"<<x<<endl
using namespace std;

#define MP make_pair
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define inc(i,a,b) for(int i=a;i<(int)b;++i)
#define pb push_back
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define bye exit(0)
#define YES puts("YES")
#define NO  puts("NO")
#define FORV(t1) for(int t1=head[u];t1;t1=Next[t1])
#define MAX(x,y) x=max(x,y)
#define MIN(x,y) x=min(x,y)
#define CLR(a,val) memset(a,val,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int>pii;
void R() {}
template<class T> void _R(T &x) {cin>>x;}
void _R(signed &x) {scanf("%d", &x);}
void _R(LL &x) {scanf("%I64d", &x);}
void _R(double &x) {scanf("%lf",&x);}
void _R(char &x) {scanf(" %c",&x);}
void _R(char *x) {scanf("%s",x);}
template<class T, class... Tx> void R(T &head, Tx &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const signed &x) { printf("%d", x); }
void _W(const LL &x) { printf("%I64d", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const double EPS = 1e-7;
const int N=1e6+5;
//head
int t,n,a[100005],b[100005];
signed main(){
  int t;
  cin>>t;
  while(t--){
    scanf("%d",&n);
    rep(i,1,n) scanf("%1d",&a[i]);
    rep(i,1,n) scanf("%1d",&b[i]);
    vector<int>ans;
    int op=0,l=1,r=n+1;
    for(int i=n;i>=1;i--){
      int xx,pre,yy=b[i];
      if(op==0){
        r--;
      }
      if(op==1){
        r++;
      }

      xx=a[r]^op,pre=a[l]^op;

//      if(i==2){
//        cout<<l<<' '<<r<<endl;
//        cout<<op<<endl;
//        printf("xx=%d,pre=%d,yy=%d,\n",xx,pre,yy);
//      }
      if(xx==yy){
        continue;
      }
      if(i==1&&xx!=yy){
        ans.push_back(1);
        continue;
      }
      if(xx!=yy&&xx!=pre){
        ans.push_back(1);
        a[l]^=1;
        ans.push_back(i);
        swap(l,r);
        op^=1;
      }
      if(xx!=yy&&xx==pre){
        ans.push_back(i);
        swap(l,r);
        op^=1;
      }
    }
    if(ans.size()){
      for(int i:ans) printf("%d ",i);puts("");
    }
    if(!ans.size()) puts("0");
  }
  return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<map>
#define debug(x) cout<<#x<<":"<<x<<endl
using namespace std;

#define fi first
#define se second
#define MP make_pair
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define inc(i,a,b) for(int i=a;i<(int)b;++i)
#define pb push_back
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define bye exit(0)
#define YES puts("YES")
#define NO  puts("NO")
#define FORV(t1) for(int t1=head[u];t1;t1=Next[t1])
#define MAX(x,y) x=max(x,y)
#define MIN(x,y) x=min(x,y)
#define CLR(a,val) memset(a,val,sizeof(a))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int>pii;
void R() {}
template<class T> void _R(T &x) {cin>>x;}
void _R(signed &x) {scanf("%d", &x);}
void _R(LL &x) {scanf("%I64d", &x);}
void _R(double &x) {scanf("%lf",&x);}
void _R(char &x) {scanf(" %c",&x);}
void _R(char *x) {scanf("%s",x);}
template<class T, class... Tx> void R(T &head, Tx &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const signed &x) { printf("%d", x); }
void _W(const LL &x) { printf("%I64d", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const double EPS = 1e-7;
const int N=1e6+5;
//head
int t,n,a[100005],b[100005];
signed main(){
  int t;
  cin>>t;
  while(t--){
    scanf("%d",&n);
    rep(i,1,n) scanf("%1d",&a[i]);
    rep(i,1,n) scanf("%1d",&b[i]);
    vector<int>ans;
    int op=0,one=0;
    for(int i=n;i>=1;i--){
      int xx,yy=b[i];
      if(op==0){
        if(one==0){
          xx=a[i];
        }
        if(one==1){
          xx=a[i]^1;
          one=0;
        }
      }
      else{//op==1
        if(one==1){
          xx=a[1]^op;
        }
        if(one==0){
          xx=a[1]^op;
        }
      }
      if(xx==yy) continue;
      if(i==1&&xx!=yy){
        ans.push_back(1);
        //if(op==0)
          a[1]^=1;
        //else one=1;
        continue;
      }
      if(a[1]!=xx){
        ans.push_back(1);
        //if(op==0)
          a[1]^=1;
        //else one=1;
        ans.push_back(i);
        op^=1;
      }
      else{
        ans.push_back(i);
        op^=1;
      }
    }
    if(ans.size()){
      for(int i:ans) printf("%d ",i);puts("");
    }
    if(!ans.size()) puts("0");
  }
  return 0;
}


#include<iostream>
#include<string>
using namespace std;
int ans1[100005],ans2[100005];
int main()
{
	int t,n;
	cin >> t;
	while(t--)
	{
		int cnt = 0,cnt2 = 0;
		string s1,s2;
		cin >> n;
		cin >> s1 >> s2;
		if(n==1)
		{
			if(s1!=s2)
			cout << "1 1"<<endl;
			else
			cout << "0"<<endl;
		}
		else
		{
			if(s1==s2)
			 {cout << "0" <<endl;continue;}
			for(int i=1; i<n; i++)
			{
				if(s1[i]!=s1[i-1])
					ans1[++cnt] = i;

			}
			if(s1[n-1]!=s2[n-1])
				ans1[++cnt]=n;
			for(int i=1; i<n; i++)
			{
				if(s2[i]!=s2[i-1])
				{
				 ans2[cnt2++] = i;
				}
			}
		cout << cnt + cnt2;
		for(int i=1; i<=cnt; i++)
			cout  << " "<<ans1[i] ;
		for(int i=cnt2-1; i>=0; i--)
			cout <<" "<< ans2[i];
		cout << endl;
		}

	}
}


#include<iostream>
#include<string>
using namespace std;
int ans1[10005],ans2[10005];
int main()
{
	int t,n;
	cin >> t;
	while(t--)
	{
		int cnt = 0,cnt2 = 0;
		string s1,s2;
		cin >> n;
		cin >> s1 >> s2;
		if(n==1)
		{
			if(s1!=s2)
			cout << "1 1"<<endl;
			else
			cout << " "<<endl;
		}
		else
		{
			for(int i=1; i<n; i++)
			{
				if(s1[i]!=s1[i-1])
					ans1[++cnt] = i;

			}
			for(int i=0; i<n; i++)
			{
				if(s2[i]!=s2[i+1])
				{
				 ans2[cnt2++] = i+1;
				}
			}
		cout << cnt + cnt2<<" ";
		for(int i=1; i<=cnt; i++)
			cout << ans1[i]<< " " ;
		for(int i=cnt2-1; i>=0; i--)
			cout << ans2[i]<<" ";
		cout << endl;
		}

	}
}


#include<iostream>
#include<string>
using namespace std;
int ans1[10005],ans2[10005];
int main()
{
	int t,n;
	cin >> t;
	while(t--)
	{
		int cnt = 0,cnt2 = 0;
		string s1,s2;
		cin >> n;
		cin >> s1 >> s2;
		if(n==1)
		{
			if(s1!=s2)
			cout << "1 1"<<endl;
			else
			cout << "0"<<endl;
		}
		else
		{
			for(int i=1; i<n; i++)
			{
				if(s1[i]!=s1[i-1])
					ans1[++cnt] = i;

			}
			for(int i=0; i<n; i++)
			{
				if(s2[i]!=s2[i+1])
				{
				 ans2[cnt2++] = i+1;
				}
			}
		cout << cnt + cnt2;
		for(int i=1; i<=cnt; i++)
			cout  << " "<<ans1[i] ;
		for(int i=cnt2-1; i>=0; i--)
			cout <<" "<< ans2[i];
		cout << endl;
		}

	}
}


#include<iostream>
#include<string>
using namespace std;
int ans1[10005],ans2[10005];
int main()
{
	int t,n;
	cin >> t;
	while(t--)
	{
		int cnt = 0,cnt2 = 0;
		string s1,s2;
		cin >> n;
		cin >> s1 >> s2;
		if(n==1)
		{
			if(s1!=s2)
			cout << "1 1"<<endl;
			else
			cout << "0"<<endl;
		}
		else
		{
			if(s1==s2)
			 {cout << "0" <<endl;continue;}
			for(int i=1; i<n; i++)
			{
				if(s1[i]!=s1[i-1])
					ans1[++cnt] = i;

			}
			if(s1[n-1]!=s2[n-1])
				ans1[++cnt]=n;
			for(int i=1; i<n; i++)
			{
				if(s2[i]!=s2[i-1])
				{
				 ans2[cnt2++] = i;
				}
			}
		cout << cnt + cnt2;
		for(int i=1; i<=cnt; i++)
			cout  << " "<<ans1[i] ;
		for(int i=cnt2-1; i>=0; i--)
			cout <<" "<< ans2[i];
		cout << endl;
		}

	}
}


#include<iostream>
#include<string>
using namespace std;
int ans1[10005],ans2[10005];
int main()
{
	int t,n;
	cin >> t;
	while(t--)
	{
		int cnt = 0,cnt2 = 0;
		string s1,s2;
		cin >> n;
		cin >> s1 >> s2;
		/*if(s1[0]!=s2[0])
		{
			ans2[cnt2++]=1;
			s2[0]=s1[0];
		}*/
			for(int i=1; i<n; i++)
			{
				if(s1[i]!=s1[i-1])
					ans1[cnt++] = i;

			}
			for(int i=0; i<n; i++)
			{
				if(s2[i]!=s2[i+1])
				{
				 ans2[cnt2++] = i+1;
				}
			}
			cout << cnt + cnt2;
		for(int i=0; i<cnt; i++)
			cout << " " << ans1[i];
		for(int i=cnt2-1; i>=0; i--)
			cout << " " << ans2[i];
		cout << endl;

	}
}


#include<iostream>
#include<string>
using namespace std;
int ans1[10005],ans2[10005];
int main()
{
	int t,n;
	cin >> t;
	while(t--)
	{
		int cnt = 0,cnt2 = 0;
		string s1,s2;
		cin >> n;
		cin >> s1 >> s2;
		if(n==1)
		{
			if(s1!=s2)
			cout << "1 1"<<endl;
			else
			cout << "0"<<endl;
		}
		else
		{
			if(s1==s2)
			 {cout << "0" <<endl;continue;}
			for(int i=1; i<n; i++)
			{
				if(s1[i]!=s1[i-1])
					ans1[++cnt] = i;

			}
			for(int i=0; i<n; i++)
			{
				if(s2[i]!=s2[i+1])
				{
				 ans2[cnt2++] = i+1;
				}
			}
		cout << cnt + cnt2;
		for(int i=1; i<=cnt; i++)
			cout  << " "<<ans1[i] ;
		for(int i=cnt2-1; i>=0; i--)
			cout <<" "<< ans2[i];
		cout << endl;
		}

	}
}


#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> pll;
const int mod = 1e9 + 7;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
ll qpow(ll base, ll n){ll ans = 1; while (n){if (n & 1) ans = ans * base % mod; base = base * base % mod; n >>= 1;} return ans;}
ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}
char a[N],b[N];
int ans[N << 1], n, tot;
int main(){
	int t;
	cin >> t;
	while (t --){
		tot = 0;
		scanf("%d", &n);
		scanf("%s", a + 1);
		scanf("%s", b + 1);
		a[0] = a[1], b[n + 1] = a[n];//这样就不用特判n == 1
		for (int i = 1; i <= n; ++ i){
			if (a[i] != a[i - 1]) ans[++ tot] = i - 1;
		}
		for (int i = n; i >= 1; -- i) {
			if (b[i] != b[i + 1]) ans[++ tot] = i;
		}
		printf("%d ", tot);
		for (int i = 1; i <= tot; ++ i)  printf("%d ", ans[i]);
		puts("");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+500;
typedef long long ll;
int  a[N],b[N];
void work(int x){
    for(int i=1;i<=x;i++){
        a[i]=1-a[i];
    }
    for(int i=1;i<=x/2;i++){
        swap(a[i],a[x-i+1]);
    }
}
// bool check(int x,int y){

// }
int main(){
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        for(int i=1;i<=n;i++){
        scanf("%1d",&a[i]);
        }
        for(int i=1;i<=n;i++){
        scanf("%1d",&b[i]);
        }

        vector<int>v;
        for(int i=n;i>=1;i--){

            if(a[i]==b[i])continue;
            if(1-a[1]== b[i]){
                work(i);v.push_back(i);
             continue;
            }
            for(int j=i-1;j>=1;j--){
                if( (1-(1-a[j]) )==b[i]){
                    work(j);
                    v.push_back(j);
                    work(i);
                    v.push_back(i);
                    break;
                }
            }

        }
    cout<<v.size()<<" ";
    for(int i=0;i<v.size();i++){
        if(i)cout<<" ";
        cout<<v[i];
    }

    cout<<endl;

    }

    // system("pause");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+500;
typedef long long ll;
int  a[N],b[N];
int main(){
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        for(int i=1;i<=n;i++){
            scanf("%1d",&a[i]);
        }
        for(int i=1;i<=n;i++){
            scanf("%1d",&b[i]);
        }
    vector<int>va,vb;
    for(int i=1;i<n;i++){
        if(a[i]!=a[i+1])va.push_back(i);
        if(b[i]!=b[i+1])vb.push_back(i);
    }
    if(a[n]==1)va.push_back(n);
    if(b[n]==1)vb.push_back(n);
    va.insert(va.end(),vb.rbegin(),vb.rend());
    for(int i=0;i<va.size();i++){
        if(i)cout<<" ";
        cout<<va[i];
    }
    cout<<endl;

    }

    // system("pause");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+500;
typedef long long ll;
int  a[N],b[N];
int main(){
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        for(int i=1;i<=n;i++){
            scanf("%1d",&a[i]);
        }
        for(int i=1;i<=n;i++){
            scanf("%1d",&b[i]);
        }
    vector<int>va,vb;
    for(int i=1;i<n;i++){
        if(a[i]!=a[i+1])va.push_back(i);
        if(b[i]!=b[i+1])vb.push_back(i);
    }
    if(a[n]==1)va.push_back(n);
    if(b[n]==1)vb.push_back(n);
    va.insert(va.end(),vb.rbegin(),vb.rend());
    cout<<va.size()<<" ";
    for(int i=0;i<va.size();i++){
        if(i)cout<<" ";
        cout<<va[i];
    }
    cout<<endl;

    }

    // system("pause");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+500;
typedef long long ll;
int  a[N],b[N];
int main(){
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        for(int i=1;i<=n;i++){
            scanf("%1d",&a[i]);
        }
        for(int i=1;i<=n;i++){
            scanf("%1d",&b[i]);
        }
    vectot<int>va,vb;
    for(int i=1;i<n;i++){
        if(a[i]!=a[i+1])va.push_back(i);
        if(b[i]!=b[i+1])vb.push_back(i);
    }
    if(a[n]==1)va.push_back(n);
    if(b[n]==1)vb.push_back(n);
    va.insert(va.end(),vb.rbegin(),vb.rend());
    for(int i=0;i<va.size();i++){
        if(i)cout<<" ";
        cout<<va[i];
    }
    cout<<endl;
    }

    // system("pause");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+500;
typedef long long ll;
int  a[N],b[N];
int main(){
    int t;cin>>t;
    while(t--){
        int n;cin>>n;
        for(int i=1;i<=n;i++){
            scanf("%1d",&a[i]);
        }
        for(int i=1;i<=n;i++){
            scanf("%1d",&b[i]);
        }
    vector<int>va,vb;
    for(int i=1;i<n;i++){
        if(a[i]!=a[i+1])va.push_back(i);
        if(b[i]!=b[i+1])vb.push_back(i);
    }
    if(a[n]==1)va.push_back(n);
    if(b[n]==1)vb.push_back(n);
    cout<<va.size()<<" ";
    va.insert(va.end(),vb.rbegin(),vb.rend());
    for(int i=0;i<va.size();i++){
        if(i)cout<<" ";
        cout<<va[i];
    }
    cout<<endl;

    }

    // system("pause");
    return 0;
}


    #include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    void funccall(string &a, string &b, vlli &oper)
    {
        lli n=sz(a);
        blli(i,n-1,0)
        {
            if(a[i]==b[i])continue;
            if(i==0)
            {
                oper.pb(1);
                continue;
            }
            char temp1,temp2;
            if(i>1)
            {
                char temp1=a[0];
                char temp2=a[i];
                if(temp1=='0')a[i]='1';
                else a[i]='0';
                if(temp2=='0')a[0]='1';
                else a[0]='0';
                oper.pb(i+1);
            }
            if(b[i]==a[0])
            {
                oper.pb(1);
                temp1=a[0];
                if(temp1=='0')a[0]='1';
                else a[0]='0';
            }
            oper.pb(i+1);
            temp1=a[0];
            temp2=a[i];
            if(temp1=='0')a[i]='1';
            else a[i]='0';
            if(temp2=='0')a[0]='1';
            else a[0]='0';
        }
    }
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        int t;cin>>t;
        while(t--)
        {
            lli n;cin>>n;
            string a;string b;
            cin>>a;
            cin>>b;
            string var=a;
            vlli oper;
            funccall(var,b,oper);
            lli szoper=sz(oper);
            lli count=0;
            while(count<10 && szoper>2*n)
            {
                var=a;
                oper.clear();
                oper.pb(n-count);
                flli(i,0,n-count-1)
                {
                    if(var[i]=='0')var[i]='1';
                    else var[i]='0';
                }
                count++;
                reverse(var.begin(),var.begin()+n-count);
                funccall(var,b,oper);
                szoper=sz(oper);
            }
            //check if we have two same operation then replace it by one
            vlli final;
            lli index=0;
            while(index<szoper)
            {
                lli tem=oper[index];
                lli tempcount=0;
                while(index<szoper && tem==oper[index])
                {
                    index++;
                    tempcount++;
                }
                if(tempcount%2!=0)final.pb(tem);
            }
            szoper=sz(final);
            cout<<szoper<<" ";
            tr(final,it)cout<<*it<<" ";cout<<endl;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }


    #include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    void funccall(string &a, string &b, vlli &oper)
    {
        lli n=sz(a);
        blli(i,n-1,0)
        {
            if(a[i]==b[i])continue;
            if(i==0)
            {
                oper.pb(1);
                continue;
            }
            char temp1=a[0];
            char temp2=a[i];
            if(temp1=='0')a[i]='1';
            else a[i]='0';
            if(temp2=='0')a[0]='1';
            else a[0]='0';
            oper.pb(i+1);
            if(b[i]==a[0])
            {
                oper.pb(1);
                temp1=a[0];
                if(temp1=='0')a[0]='1';
                else a[0]='0';
            }
            oper.pb(i+1);
            temp1=a[0];
            temp2=a[i];
            if(temp1=='0')a[i]='1';
            else a[i]='0';
            if(temp2=='0')a[0]='1';
            else a[0]='0';
        }
    }
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        int t;cin>>t;
        while(t--)
        {
            lli n;cin>>n;
            string a;string b;
            cin>>a;
            cin>>b;
            string var=a;
            vlli oper;
            funccall(var,b,oper);
            lli szoper=sz(oper);
            if(szoper>2*n)
            {
                oper.clear();
                oper.pb(n);
                flli(i,0,n-1)
                {
                    if(a[i]=='0')a[i]='1';
                    else a[i]='0';
                }
                reverse(all(a));
                funccall(a,b,oper);
                szoper=sz(oper);
            }
            cout<<szoper<<" ";
            tr(oper,it)cout<<*it<<" ";cout<<endl;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }


    #include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    void funccall(string &a, string &b, vlli &oper)
    {
        lli n=sz(a);
        blli(i,n-1,0)
        {
            if(a[i]==b[i])continue;
            if(i==0)
            {
                oper.pb(1);
                continue;
            }
            char temp1=a[0];
            char temp2=a[i];
            if(temp1=='0')a[i]='1';
            else a[i]='0';
            if(temp2=='0')a[0]='1';
            else a[0]='0';
            oper.pb(i+1);
            if(b[i]==a[0])
            {
                oper.pb(1);
                temp1=a[0];
                if(temp1=='0')a[0]='1';
                else a[0]='0';
            }
            oper.pb(i+1);
            temp1=a[0];
            temp2=a[i];
            if(temp1=='0')a[i]='1';
            else a[i]='0';
            if(temp2=='0')a[0]='1';
            else a[0]='0';
        }
    }
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        int t;cin>>t;
        while(t--)
        {
            lli n;cin>>n;
            string a;string b;
            cin>>a;
            cin>>b;
            string var=a;
            vlli oper;
            funccall(var,b,oper);
            lli szoper=sz(oper);
            if(szoper>2*n)
            {
                oper.clear();
                oper.pb(n);
                flli(i,0,n-1)
                {
                    if(a[i]=='0')a[i]='1';
                    else a[i]='0';
                }
                reverse(all(a));
                funccall(a,b,oper);
                szoper=sz(oper);
            }
            //check if we have two same operation then replace it by one
            vlli final;
            lli index=0;
            while(index<szoper)
            {
                lli tem=oper[index];
                lli tempcount=0;
                while(index<szoper && tem==oper[index])
                {
                    index++;
                    tempcount++;
                }
                if(tempcount%2!=0)final.pb(tem);
            }
            szoper=sz(final);
            cout<<szoper<<" ";
            tr(final,it)cout<<*it<<" ";cout<<endl;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }


    #include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    void funccall(string &a, string &b, vlli &oper)
    {
        lli n=sz(a);
        blli(i,n-1,0)
        {
            if(a[i]==b[i])continue;
            if(i==0)
            {
                oper.pb(1);
                continue;
            }
            char temp1,temp2;
            if(i>1)
            {
                char temp1=a[0];
                char temp2=a[i];
                if(temp1=='0')a[i]='1';
                else a[i]='0';
                if(temp2=='0')a[0]='1';
                else a[0]='0';
                oper.pb(i+1);
            }
            if(b[i]==a[0])
            {
                oper.pb(1);
                temp1=a[0];
                if(temp1=='0')a[0]='1';
                else a[0]='0';
            }
            oper.pb(i+1);
            temp1=a[0];
            temp2=a[i];
            if(temp1=='0')a[i]='1';
            else a[i]='0';
            if(temp2=='0')a[0]='1';
            else a[0]='0';
        }
    }
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        int t;cin>>t;
        while(t--)
        {
            lli n;cin>>n;
            string a;string b;
            cin>>a;
            cin>>b;
            string var=a;
            vlli oper;
            funccall(var,b,oper);
            lli szoper=sz(oper);
            lli count=0;
            while(count<10 && szoper>2*n)
            {
                var=a;
                oper.clear();
                oper.pb(n-count);
                flli(i,0,n-count-1)
                {
                    if(var[i]=='0')var[i]='1';
                    else var[i]='0';
                }
                reverse(var.begin(),var.begin()+n-count);
                count++;
                funccall(var,b,oper);
                szoper=sz(oper);
            }
            //check if we have two same operation then replace it by one
            vlli final;
            lli index=0;
            while(index<szoper)
            {
                lli tem=oper[index];
                lli tempcount=0;
                while(index<szoper && tem==oper[index])
                {
                    index++;
                    tempcount++;
                }
                if(tempcount%2!=0)final.pb(tem);
            }
            szoper=sz(final);
            cout<<szoper<<" ";
            tr(final,it)cout<<*it<<" ";cout<<endl;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }


    #include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    void funccall(string &a, string &b, vlli &oper)
    {
        lli n=sz(a);
        blli(i,n-1,0)
        {
            if(a[i]==b[i])continue;
            if(i==0)
            {
                oper.pb(1);
                continue;
            }
            char temp1=a[0];
            char temp2=a[i];
            if(temp1=='0')a[i]='1';
            else a[i]='0';
            if(temp2=='0')a[0]='1';
            else a[0]='0';
            oper.pb(i+1);
            if(b[i]==a[0])
            {
                oper.pb(1);
                temp1=a[0];
                if(temp1=='0')a[0]='1';
                else a[0]='0';
            }
            oper.pb(i+1);
            temp1=a[0];
            temp2=a[i];
            if(temp1=='0')a[i]='1';
            else a[i]='0';
            if(temp2=='0')a[0]='1';
            else a[0]='0';
        }
    }
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        int t;cin>>t;
        while(t--)
        {
            lli n;cin>>n;
            string a;string b;
            cin>>a;
            cin>>b;
            string var=a;
            vlli oper;
            funccall(var,b,oper);
            lli szoper=sz(oper);
            if(szoper>2*n)
            {
                oper.clear();
                oper.pb(n);
                flli(i,0,n-1)
                {
                    if(a[i]=='0')a[i]='1';
                    else a[i]='0';
                }
                reverse(all(a));
                funccall(a,b,oper);
                szoper=sz(oper);
            }
            //check if we have two same operation then replace it by one
            vlli final;
            lli index=0;
            while(index<szoper)
            {
                lli tem=oper[index];
                lli tempcount=0;
                final.pb(tem);
                while(index<szoper && tem==oper[index])
                {
                    index++;
                    tempcount++;
                }
                if(tempcount%2!=0 && tempcount>1)final.pb(tem);
            }
            szoper=sz(final);
            cout<<szoper<<" ";
            tr(final,it)cout<<*it<<" ";cout<<endl;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }


    #include<bits/stdc++.h>
    #include<algorithm>
    #include<cmath>
    #include<climits>
    using namespace std;
    typedef long long int lli;
    typedef vector<int> vi;
    typedef vector<long long int> vlli;
    typedef pair<int,int> pii;
    typedef pair<long long int,long long int> plli;
    typedef vector< vi > vvi ;
    typedef vector< vlli > vvlli  ;
    #define fi(i,a,b) for(int i=a;i<=b;i++)
    #define flli(i,a,b) for(long long int i=a;i<=b;i++)
    #define bi(i,a,b) for(int i=a;i>=b;i--)
    #define blli(i,a,b) for(long long int i=a;i>=b;i--)
    #define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
    #define all(x) x.begin(),x.end()
    #define sz(x) x.size()
    #define pi 2*acos(0.0)
    #define pb push_back
    #define tr(v,it) for(decltype(v.begin()) it=v.begin();it!=v.end();it++)
    #define present(v,num) (v.find(num)!=v.end())
    #define cpresent(v,num) (find(v.begin(),v.end(),num)!=v.end())
    #define pq priority_queue
    #define mp make_pair
    const int inf=INT_MAX;
    const lli INF =LLONG_MAX;
    const lli mod = 1e9+7;
    void funccall(string &a, string &b, vlli &oper)
    {
        lli n=sz(a);
        blli(i,n-1,0)
        {
            if(a[i]==b[i])continue;
            if(i==0)
            {
                oper.pb(1);
                continue;
            }
            char temp1,temp2;
            if(i>1)
            {
                char temp1=a[0];
                char temp2=a[i];
                if(temp1=='0')a[i]='1';
                else a[i]='0';
                if(temp2=='0')a[0]='1';
                else a[0]='0';
                oper.pb(i+1);
            }
            if(b[i]==a[0])
            {
                oper.pb(1);
                temp1=a[0];
                if(temp1=='0')a[0]='1';
                else a[0]='0';
            }
            oper.pb(i+1);
            temp1=a[0];
            temp2=a[i];
            if(temp1=='0')a[i]='1';
            else a[i]='0';
            if(temp2=='0')a[0]='1';
            else a[0]='0';
        }
    }
    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        fast;
        int t;cin>>t;
        while(t--)
        {
            lli n;cin>>n;
            string a;string b;
            cin>>a;
            cin>>b;
            string var=a;
            vlli oper;
            funccall(var,b,oper);
            lli szoper=sz(oper);
            var=a;
            if(szoper>2*n)
            {
                oper.clear();
                oper.pb(n);
                flli(i,0,n-1)
                {
                    if(var[i]=='0')var[i]='1';
                    else var[i]='0';
                }
                reverse(all(var));
                funccall(var,b,oper);
                szoper=sz(oper);
            }
            var=a;
            if(szoper>2*n)
            {
                oper.clear();
                oper.pb(n-1);
                flli(i,0,n-2)
                {
                    if(var[i]=='0')var[i]='1';
                    else var[i]='0';
                }
                reverse(var.begin(),var.begin()+n-1);
                funccall(var,b,oper);
                szoper=sz(oper);
            }
            //check if we have two same operation then replace it by one
            vlli final;
            lli index=0;
            while(index<szoper)
            {
                lli tem=oper[index];
                lli tempcount=0;
                while(index<szoper && tem==oper[index])
                {
                    index++;
                    tempcount++;
                }
                if(tempcount%2!=0)final.pb(tem);
            }
            szoper=sz(final);
            cout<<szoper<<" ";
            tr(final,it)cout<<*it<<" ";cout<<endl;
        }
        cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
        return 0;
    }