#include <stdio.h>
int main()
{
    long long int t,n,m,lat=0,sq=0;
    scanf("%lld",&t);
    while(t--)
    {

     scanf("%lld %lld",&n,&m);
     sq=n*m;
     if(sq%2==0)
     {
         lat=sq/2;
     }
     else
     {
         lat=sq/2 +1;
     }
     printf("%lld",lat);
    }
    return 0;
}


#include <stdio.h>
#include <math.h>
int main()
{
    int t,n,m,lat=0;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d",&n,&m);
        double a,b;
        a=n;
        b=m;
        lat=ceil((a*b)/2);
        printf("%d\n",lat);
    }
    return 0;
}


#include <stdio.h>
#include <math.h>
int main()
{
    int t,n,m,lat=0;
    scanf("%d",&t);
    while(t--)
    {

     scanf("%d %d",&n,&m);

     lat = ceil((n*m) / 2);
     printf("%d",lat);
    }
    return 0;
}


#include <stdio.h>
int main()
{
    int t,n,m,lat=0,sq=0;
    scanf("%d",&t);
    while(t--)
    {
     scanf("%d %d",&n,&m);
     sq=n*m;
     if(sq%2==0)
     {
         lat=sq/2;
     }
     else
     {
         lat=sq/2 +1;
     }
     printf("%d",lat);
    }
    return 0;
}


#include <stdio.h>
int main()
{
    int t,n,m,lat=0;
    scanf("%d",&t);
    while(t--)
    {

     scanf("%d %d",&n,&m);

     lat = ceil((n*m) / 2);
     printf("%d",lat);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int test;
	cin >> test;

	for (int tt = 0; tt < test; tt++) {
		int n, m;
		cin >> n >> m;

		if(m%2==0 || n%2==0)
		{
		    cout << n*(m/2) << endl;
		}

		else
		{

		            cout << ((n*m)+1)/2 << endl;

		}

	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int test;
	cin >> test;

	for (int tt = 0; tt < test; tt++) {
		int n, m;
		cin >> n >> m;

		if(m%2==0 || n%2==0)
		{
		    cout << n*(m/2) << endl;
		}

		else
		{

		        if(n==1 && m==1)
		        {
		            cout << 1 << endl;
		        }
		        else
		        {
		            cout << n*((m-1)/2)+((n/2)+1) << endl;
		        }

		}

	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int test;
	cin >> test;

	for (int tt = 0; tt < test; tt++) {
		int n, m;
		cin >> n >> m;

		if(m%2==0 || n%2==0)
		{
		    cout << m/2*n << endl;
		}

		else
		{

		        if(n==1 && m==1)
		        {
		            cout << 1 << endl;
		        }
		        else
		        {
		            cout << n*((m-1)/2)+((n/2)+1) << endl;
		        }

		}

	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int test;
	cin >> test;

	for (int tt = 0; tt < test; tt++) {
		int n, m;
		cin >> n >> m;

		if(m%2==0 || n%2==0)
		{
		    cout << (n*m)/2 << endl;
		}

		else
		{

		        cout << ((n*m)+1)/2 << endl;
		}

	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int test;
	cin >> test;

	for (int tt = 0; tt < test; tt++) {
		int n, m;
		cin >> n >> m;

		if(m%2==0)
		{
		    cout << (n*m)/2 << endl;
		}

		else
		{
		    if(n%2==0)
		    {
		        cout << n*(m-1/2)+n/2 << endl;
		    }
		    else
		    {
		        if(n==1 && m==1)
		        {
		            cout << 1 << endl;
		        }
		        else
		        {
		            cout << n*((m-1)/2)+((n/2)+1) << endl;
		        }
		    }
		}

	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int test;
	cin >> test;

	for (int tt = 0; tt < test; tt++) {
		int n, m;
		cin >> n >> m;

		if(m%2==0)
		{
		    cout << m/2*n << endl;
		}

		else
		{
		    if(n%2==0)
		    {
		        cout << n*(m-1/2)+n/2 << endl;
		    }
		    else
		    {
		        if(n==1 && m==1)
		        {
		            cout << 1 << endl;
		        }
		        else
		        {
		            cout << n*((m-1)/2)+((n/2)+1) << endl;
		        }
		    }
		}

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define L long int
#define IM INT_MAX
#define Im INT_MIN
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main(){
fast;

int t;
cin>>t;

while(t--){
    LL n,m;
    cin>>n>>m;
    if(n==1 && m==1)cout<<1<<endl;
    else{
        LL x=m/2;
        if(m%2==0)cout<<n*x<<endl;
        else cout<<(n*x)+ceil((double(n)/2))<<endl;
    }
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define L long int
#define IM INT_MAX
#define Im INT_MIN
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main(){
fast;

int t;
cin>>t;

while(t--){
    LL n,m;
    cin>>n>>m;
    LL x=(n*m);
    if(x%2==0)cout<<x/2<<endl;
    else cout<<(x/2)+1<<endl;
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define L long int
#define IM INT_MAX
#define Im INT_MIN
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main(){
fast;

int t;
cin>>t;

while(t--){
    LL n,m;
    cin>>n>>m;
    if(n==1 && m==1)cout<<1<<endl;
    else if(n==1 && m>1)cout<<ceil((double(m)/2))<<endl;
    else if(n>1 && m==1)cout<<ceil((double(n)/2))<<endl;
    else if(n%2==0 && m%2==0){
        LL ans=(m/2)*n;
        cout<<ans<<endl;
    }
    else{
        if(n>m)swap(n,m);
        LL x=m/2;
        LL ans=(x*n);
        ans+=( ceil((double)n/2) );
        cout<<ans<<endl;
    }
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define L long int
#define IM INT_MAX
#define Im INT_MIN
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main(){
fast;

int t;
cin>>t;

while(t--){
    LL n,m;
    cin>>n>>m;
    if(n==1 && m==1)cout<<1<<endl;
    else if(n==1 && m>1)cout<<ceil((double(m)/2))<<endl;
    else if(n>1 && m==1)cout<<ceil((double(n)/2))<<endl;
    else{
        LL x=n/2;
        LL ans=(x*m);
        if(n%2!=0)ans+=(m-1);
        cout<<ans<<endl;
    }
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define L long int
#define IM INT_MAX
#define Im INT_MIN
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main(){
fast;

int t;
cin>>t;

while(t--){
    LL n,m;
    cin>>n>>m;
    if(n==1 && m==1)cout<<1<<endl;
    else if(n==1 && m>1)cout<<m-1<<endl;
    else if(n>1 && m==1)cout<<n-1<<endl;
    else{
        LL x=n/2;
        LL ans=(x*m);
        if(n%2!=0)ans+=(m-1);
        cout<<ans<<endl;
    }
}
return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define L long int
#define IM INT_MAX
#define Im INT_MIN
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

int main(){
fast;

int t;
cin>>t;

while(t--){
    LL n,m;
    cin>>n>>m;
    if(n==1 && m==1)cout<<1<<endl;
    else if(n==1 && m>1)cout<<ceil((double(m)/2))<<endl;
    else if(n>1 && m==1)cout<<ceil((double(n)/2))<<endl;
    else{
        if(n%2==0 && m%2!=0){
            LL ans=(n/2);
            ans+=(m-1);
            cout<<ans<<endl;
        }
        else if(n%2!=0 && m%2==0){
            LL ans=(m/2);
            ans+=(n-1);
            cout<<ans<<endl;
        }
        else if(n%2==0 && m%2==0){
            cout<<(n/2)*m<<endl;
        }
        else{
            if(n<m)swap(n,m);
            LL x=n/2;
            LL ans=(m*x);
            ans+=(m-1);
            cout<<ans<<endl;
        }
    }
}
return 0;
}


#include <bits/stdc++.h>
using namespace std ;

int main () {
       int  t ; long long n , a , b , m ;
        cin >> t  ;
        while (t--) {
        cin >> n >> m ;
            if ( n == 1 || m == 1 ) {
                if ( n == 1 ) {
                        cout << ceil (m/2.0) << endl ;
                }else {
                    cout << ceil (m/2.0) << endl ;
                }
                continue ;
            }
        if (  n % 2 == 0 || m % 2== 0 ) {
                if (n%2 == 0 ) {
                    cout << (n/2) * m << endl ;
                }else {
                cout << (m/2) * n << endl ;
                    }

            continue ;
        }

        n -- ;
       cout << (n/2) * m +  ceil (m/2.0)  << endl ;

        }
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;

int main () {
       int  t ; long long n , a , b , m ;
        cin >> t  ;
        while (t--) {
        cin >> n >> m ;

        cout << ceil (m*n /2.0 ) <<endl ;
        }
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;

int main () {
       int  t ; long long n , a , b , m ;
        cin >> t  ;
        while (t--) {
        cin >> n >> m ;

        cout << ceil ((m*n) /(1.0 * 2 ) ) <<endl ;
        }
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;

int main () {
       int  t ; long long n , a , b , m ;
        cin >> t  ;
        while (t--) {
        cin >> n >> m ;

                long long res = n * m ;
                if ( res % 2 == 0 ) {
                    cout << res / 2 << endl ;
                }
                else
                    cout << res / 2  + 1 << endl ;

        }
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;

int main () {
       int  t ; long long n , a , b , m ;
        cin >> t  ;
        while (t--) {
        cin >> n >> m ;
            if ( n == 1 || m == 1 ) {
                if ( n == 1 ) {
                        cout << ceil (m/2.0) << endl ;
                }else {
                    cout << ceil (m/2.0) << endl ;
                }
                continue ;
            }
        if (  n % 2 == 0 || m % 2== 0 ) {
                if (n%2 == 0 ) {
                    cout << (n/2) * m << endl ;
                }else {
                cout << (m/2) * n << endl ;
                    }

            continue ;
        }

       cout << min (  ((n-1)/2) * m +  ceil (m/2.0), ((m-1)/2 ) * n +  ceil (n/2.0))  << endl ;

        }
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;

int main () {
       int  t ; long long n , a , b , m ;
        cin >> t  ;
        while (t--) {
        cin >> n >> m ;

        cout << ceil (m*n /(1.0 * 2 ) ) <<endl ;
        }
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;

int main () {
       int  t ; long long n , a , b , m ;
        cin >> t  ;
        while (t--) {
        cin >> n >> m ;
            if ( n == 1 || m == 1 ) {
                if ( n == 1 ) {
                        cout << ceil (m/2.0) << endl ;
                }else {
                    cout << ceil (n/2.0) << endl ;
                }
                continue ;
            }
        if (  n % 2 == 0 || m % 2== 0 ) {
                if (n%2 == 0 ) {
                    cout << (n/2) * m << endl ;
                }else {
                cout << (m/2) * n << endl ;
                    }

            continue ;
        }

       cout << min (  ceil ((n-1)/2.0) * m +  ceil (m/2.0), ceil ((m-1)/2.0 ) * n +  ceil (n/2.0))  << endl ;

        }
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;

int main () {
       int  t ; long long n , a , b , m ;
        cin >> t  ;
        while (t--) {
        cin >> n >> m ;
            if ( n == 1 || m == 1 ) {
                if ( n == 1 ) {
                        cout << ceil (m/2.0) << endl ;
                }else {
                    cout << ceil (n/2.0) << endl ;
                }
                continue ;
            }
        if (  n % 2 == 0 || m % 2== 0 ) {
                if (n%2 == 0 ) {
                    cout << (n/2) * m << endl ;
                }else {
                cout << (m/2) * n << endl ;
                    }

            continue ;
        }

       cout << min (  ((n-1)/2) * m +  ceil (m/2.0), ((m-1)/2 ) * n +  ceil (n/2.0))  << endl ;

        }
    return 0 ;
}


#include <bits/stdc++.h>
using namespace std ;

int main () {
       int  t ; long long n , a , b , m ;
        cin >> t  ;
        while (t--) {
        cin >> n >> m ;
            if ( n == 1 || m == 1 ) {
                if ( n == 1 ) {
                        cout << ceil (m/2.0) << endl ;
                }else {
                    cout << ceil (n/2.0) << endl ;
                }
                continue ;
            }
        if (  n % 2 == 0 || m % 2== 0 ) {
                if (n%2 == 0 ) {
                    cout << (n/2) * m << endl ;
                }else
                cout << (m/2) * n << endl ;

            continue ;
        }

       cout << min (  (n/2) * m +  ceil (m/2.0), ( m/2 ) * n +  ceil (n/2.0))  << endl ;

        }
    return 0 ;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;

int main(){
    int t;
    cin>>t;
    for (int i=0;i<t;i++){
        double n,m;
        cin>>n>>m;
        double a=(n/2)*(m/2);
        cout<<ceil(a)<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;

int main(){
    int t;
    cin>>t;
    for (int i=0;i<t;i++){
        double n,m;
        cin>>n>>m;
        double a=m*n;
        cout<<ceil(a/2)<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;

int main(){
    int t;
    cin>>t;
    for (int i=0;i<t;i++){
        double n,m;
        cin>>n>>m;
        double a=(m*n)/2;
        cout<<ceil(a)<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
using namespace std;

int main(){
    int t;
    cin>>t;
    for (int i=0;i<t;i++){
        double n,m;
        cin>>n>>m;
        double a=(m*n)/2;
        cout<<ceil(a);
    }
    return 0;
}


#include<bits/stdc++.h>
#include<cmath>
typedef long long LL;
using namespace std;

int main(){
    int t;
    cin>>t;
    for (int i=0;i<t;i++){
        LL n,m;
        cin>>n>>m;
        LL a=(m*n);
        if(a%2==0){
            cout<<a/2<<"\n";
        }
        else
            cout<<1+(a/2)<<"\n";

    }
    return 0;
}


//21/07/2020
/*A step of a tortoise in search of happiness and true act of goodwill.!*/
//confidence and consistency are key weapons
/*
When I get older
I will be stronger
They'll call me freedom
Tust like a wavin flag
And then it goes back
And then it goes back
*/
#include<bits/stdc++.h>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\n");
#define en '\n'

#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll x,y;
};
struct cmp{
    bool operator()(const Node &a,const Node &b)const{
        if(a.x==b.x) return a.y<b.y;
        else return a.x>b.x;
    }
};

//Algos
template<typename T> using Pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

/*Containers*/
priority_queue<ll,deque<ll>,greater<ll>>pq;
set<Node,cmp>st1;
map<Node,ll,cmp>mp1;
priority_queue<Node,deque<Node>,cmp>pq1;
Pbds<ll>ost;

string a,b;

void RE(ll in){
    for(ll i=0;i<=in/2;i++){
        swap(a[i],a[in-i]);
    }
}
void Toggle(ll in){
    for(ll i=0;i<=in;i++){
        if(a[i]=='1') a[i]='0';
        else a[i]='1';
    }
}

int main(){
    _fastio
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        cin>>a>>b;
        string t="x";
        t+=a;
        a=t;
        t="x";
        t+=b;
        b=t;
        vector<ll>ans;
        ll tog[n+10];
        ll in=n;
        ll cnt=1;
        ll tot=0;
        for(ll i=1;i<=n;i++){
            if(n%2){
                if((a[cnt]==b[in]&&(tot)%2==0)||(a[cnt]!=b[in]&&(tot)%2==1)){
                    ans.emplace_back(1LL);
                    ans.emplace_back(in);
                }
                else{
                    ans.emplace_back(in);
                }
            }
            else{
                if((a[n-cnt+1]==b[in]&&(tot)%2==0)||(a[n-cnt+1]!=b[in]&&(tot)%2==1)){
                    ans.emplace_back(1LL);
                    ans.emplace_back(in);
                }
                else{
                    ans.emplace_back(in);
                }
                cnt++;
            }
            tot++;
            in--;
        }
        //cout<<a<<" for "<<b<<en;

        cout<<ans.size()<<' ';
        for(auto i:ans){
            cout<<i<<' ';
        }
        cout<<en;
    }
    return 0;
}


//21/07/2020
/*A step of a tortoise in search of happiness and true act of goodwill.!*/
//confidence and consistency are key weapons
/*
When I get older
I will be stronger
They'll call me freedom
Tust like a wavin flag
And then it goes back
And then it goes back
*/
#include<bits/stdc++.h>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\n");
#define en '\n'

#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll x,y;
};
struct cmp{
    bool operator()(const Node &a,const Node &b)const{
        if(a.x==b.x) return a.y<b.y;
        else return a.x>b.x;
    }
};

//Algos
template<typename T> using Pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

/*Containers*/
priority_queue<ll,deque<ll>,greater<ll>>pq;
set<Node,cmp>st1;
map<Node,ll,cmp>mp1;
priority_queue<Node,deque<Node>,cmp>pq1;
Pbds<ll>ost;

string a,b;

int main(){
    _fastio
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        cin>>a>>b;
        vector<ll>ans;
        ll in=n-1;
        ll cnt=0;
        ll tot=0;
        for(ll i=1;i<=n;i++){
            if(n%2){
                if((a[cnt]==b[in]&&(tot)%2==0)||(a[cnt]!=b[in]&&(tot)%2==1)){
                    ans.emplace_back(1LL);
                    ans.emplace_back(in+1);
                }
                else{
                    ans.emplace_back(in+1);
                }
            }
            else{
                if((a[n-cnt-1]==b[in]&&(tot)%2==0)||(a[n-cnt-1]!=b[in]&&(tot)%2==1)){
                    ans.emplace_back(1LL);
                    ans.emplace_back(in+1);
                }
                else{
                    ans.emplace_back(in+1);
                }
                cnt++;
            }
            tot++;
            in--;
        }
        //cout<<a<<" for "<<b<<en;

        cout<<ans.size()<<' ';
        for(auto i:ans){
            cout<<i<<' ';
        }
        cout<<en;
    }
    return 0;
}


//21/07/2020
/*A step of a tortoise in search of happiness and true act of goodwill.!*/
//confidence and consistency are key weapons
/*
When I get older
I will be stronger
They'll call me freedom
Tust like a wavin flag
And then it goes back
And then it goes back
*/
#include<bits/stdc++.h>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\n");
#define en '\n'

#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll x,y;
};
struct cmp{
    bool operator()(const Node &a,const Node &b)const{
        if(a.x==b.x) return a.y<b.y;
        else return a.x>b.x;
    }
};

//Algos
template<typename T> using Pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

/*Containers*/
priority_queue<ll,deque<ll>,greater<ll>>pq;
set<Node,cmp>st1;
map<Node,ll,cmp>mp1;
priority_queue<Node,deque<Node>,cmp>pq1;
Pbds<ll>ost;

string a,b;

int main(){
    _fastio
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        cin>>a>>b;
        vector<ll>ans;
        ll in=n-1;
        ll cnt=0;
        ll tot=0;
        for(ll i=1;i<=n;i++){
            if(n%2){
                if((a[cnt]==b[in]&&(tot)%2==1)||(a[cnt]!=b[in]&&(tot)%2==0)){
                    ans.emplace_back(1LL);
                    ans.emplace_back(in+1);
                }
                else{
                    ans.emplace_back(in+1);
                }
            }
            else{
                if((a[n-cnt-1]==b[in]&&(tot)%2==1)||(a[n-cnt-1]!=b[in]&&(tot)%2==0)){
                    ans.emplace_back(1LL);
                    ans.emplace_back(in+1);
                }
                else{
                    ans.emplace_back(in+1);
                }
                cnt++;
            }
            tot++;
            in--;
        }
        //cout<<a<<" for "<<b<<en;

        cout<<ans.size()<<' ';
        for(auto i:ans){
            cout<<i<<' ';
        }
        cout<<en;
    }
    return 0;
}


//21/07/2020
/*A step of a tortoise in search of happiness and true act of goodwill.!*/
//confidence and consistency are key weapons
/*
When I get older
I will be stronger
They'll call me freedom
Tust like a wavin flag
And then it goes back
And then it goes back
*/
#include<bits/stdc++.h>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\n");
#define en '\n'

#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll x,y;
};
struct cmp{
    bool operator()(const Node &a,const Node &b)const{
        if(a.x==b.x) return a.y<b.y;
        else return a.x>b.x;
    }
};

//Algos
template<typename T> using Pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

/*Containers*/
priority_queue<ll,deque<ll>,greater<ll>>pq;
set<Node,cmp>st1;
map<Node,ll,cmp>mp1;
priority_queue<Node,deque<Node>,cmp>pq1;
Pbds<ll>ost;

string a,b;

void RE(ll in){
    for(ll i=0;i<=in/2;i++){
        swap(a[i],a[in-i]);
    }
}
void Toggle(ll in){
    for(ll i=0;i<=in;i++){
        if(a[i]=='1') a[i]='0';
        else a[i]='1';
    }
}

int main(){
    _fastio
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        cin>>a>>b;
        vector<ll>ans;
        ll tog[n+10];
        ll in=n-1;
        ll cnt=0;
        ll tot=0;
        for(ll i=1;i<=n-1;i++){
            if(n%2){
                if((a[cnt]==b[in]&&(tot)%2==0)||(a[cnt]!=b[in]&&(tot)%2==1)){
                    ans.emplace_back(1LL);
                    ans.emplace_back(in+1);
                }
                else{
                    ans.emplace_back(in+1);
                }
            }
            else{
                if((a[n-cnt]==b[in]&&(tot)%2==0)||(a[n-cnt]!=b[in]&&(tot)%2==1)){
                    ans.emplace_back(1LL);
                    ans.emplace_back(in+1);
                }
                else{
                    ans.emplace_back(in+1);
                }
                cnt++;
            }
            tot++;
            in--;
        }
        //cout<<a<<" for "<<b<<en;

        cout<<ans.size()<<' ';
        for(auto i:ans){
            cout<<i<<' ';
        }
        cout<<en;
    }
    return 0;
}


//21/07/2020
/*A step of a tortoise in search of happiness and true act of goodwill.!*/
//confidence and consistency are key weapons
/*
When I get older
I will be stronger
They'll call me freedom
Tust like a wavin flag
And then it goes back
And then it goes back
*/
#include<bits/stdc++.h>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\n");
#define en '\n'

#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll x,y;
};
struct cmp{
    bool operator()(const Node &a,const Node &b)const{
        if(a.x==b.x) return a.y<b.y;
        else return a.x>b.x;
    }
};

//Algos
template<typename T> using Pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

/*Containers*/
priority_queue<ll,deque<ll>,greater<ll>>pq;
set<Node,cmp>st1;
map<Node,ll,cmp>mp1;
priority_queue<Node,deque<Node>,cmp>pq1;
Pbds<ll>ost;

string a,b;

void RE(ll in){
    for(ll i=0;i<=in/2;i++){
        swap(a[i],a[in-i]);
    }
}
void Toggle(ll in){
    for(ll i=0;i<=in;i++){
        if(a[i]=='1') a[i]='0';
        else a[i]='1';
    }
}

int main(){
    _fastio
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        cin>>a>>b;
        string t="x";
        t+=a;
        a=t;
        t="x";
        t+=b;
        b=t;
        vector<ll>ans;
        ll tog[n+10];
        memset(tog,0,sizeof(tog));
        ll in=n;
        ll cnt=1;
        ll tot=0;
        for(ll i=1;i<=n;i++){
            if(n%2){
                if((a[cnt]==b[in]&&(tog[cnt]+tot)%2==0)||(a[cnt]!=b[in]&&(tog[cnt]+tot)%2==0)){
                    ans.emplace_back(1LL);
                    tog[cnt]++;
                    ans.emplace_back(in);
                }
                else{
                    ans.emplace_back(in);
                }
            }
            else{
                if((a[n-cnt]==b[in]&&(tog[n-cnt]+tot)%2==0)||(a[n-cnt]!=b[in]&&(tog[n-cnt]+tot)%2==0)){
                    ans.emplace_back(1LL);
                    tog[n-cnt]++;
                    ans.emplace_back(in);
                }
                else{
                    ans.emplace_back(in);
                }
                cnt++;
            }
            tot++;
            in--;
        }
        //cout<<a<<" for "<<b<<en;

        cout<<ans.size()<<' ';
        for(auto i:ans){
            cout<<i<<' ';
        }
        cout<<en;
    }
    return 0;
}


//21/07/2020
/*A step of a tortoise in search of happiness and true act of goodwill.!*/
//confidence and consistency are key weapons
/*
When I get older
I will be stronger
They'll call me freedom
Tust like a wavin flag
And then it goes back
And then it goes back
*/
#include<bits/stdc++.h>
#include<cmath>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define debug printf("Debug\n");
#define en '\n'

#define ll long long
#define ull unsigned long long

#define pi acos(-1.0)
#define mod 1000000007

#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define in_fre  freopen("in.txt", "r", stdin);
#define out_fre freopen("out.txt", "w", stdout);

struct Node{
    ll x,y;
};
struct cmp{
    bool operator()(const Node &a,const Node &b)const{
        if(a.x==b.x) return a.y<b.y;
        else return a.x>b.x;
    }
};

//Algos
template<typename T> using Pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

/*Containers*/
priority_queue<ll,deque<ll>,greater<ll>>pq;
set<Node,cmp>st1;
map<Node,ll,cmp>mp1;
priority_queue<Node,deque<Node>,cmp>pq1;
Pbds<ll>ost;

string a,b;

void RE(ll in){
    for(ll i=0;i<=in/2;i++){
        swap(a[i],a[in-i]);
    }
}
void Toggle(ll in){
    for(ll i=0;i<=in;i++){
        if(a[i]=='1') a[i]='0';
        else a[i]='1';
    }
}

int main(){
    _fastio
    ll t;
    cin>>t;
    while(t--){
        ll n;
        cin>>n;
        cin>>a>>b;
        string t="x";
        t+=a;
        a=t;
        t="x";
        t+=b;
        b=t;
        vector<ll>ans;
        ll tog[n+10];
        memset(tog,0,sizeof(tog));
        ll in=n;
        ll cnt=1;
        ll tot=0;
        for(ll i=1;i<=n;i++){
            if(n%2){
                if((a[cnt]==b[in]&&(tog[cnt]+tot)%2==0)||(a[cnt]!=b[in]&&(tog[cnt]+tot)%2==1)){
                    ans.emplace_back(1LL);
                    tog[cnt]++;
                    ans.emplace_back(in);
                }
                else{
                    ans.emplace_back(in);
                }
            }
            else{
                if((a[n-cnt]==b[in]&&(tog[n-cnt]+tot)%2==0)||(a[n-cnt]!=b[in]&&(tog[n-cnt]+tot)%2==1)){
                    ans.emplace_back(1LL);
                    tog[n-cnt]++;
                    ans.emplace_back(in);
                }
                else{
                    ans.emplace_back(in);
                }
                cnt++;
            }
            tot++;
            in--;
        }
        //cout<<a<<" for "<<b<<en;

        cout<<ans.size()<<' ';
        for(auto i:ans){
            cout<<i<<' ';
        }
        cout<<en;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

char swap(char c)
{
    return c == '0' ? '1' : '0';
}

void solve()
{
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<int> pasuxi;
    string swapwith = a;
    for(int i = n - 1; i > 0; i--)
    {
        if(a[i] == b[i]) continue;
        if(a[i] != a[0])
        {
            a[0] = swap(a[0]);
            pasuxi.push_back(1);
        }
        pasuxi.push_back(i + 1);
        //string swapwith = "";
        for(int j = i; j >= 0; j--)
        {
            swapwith[i - j] = swap(a[j]);
        }
        for(int j = 0; j < i; j++)
            a[j] = swapwith[j];
    }
    if(a[0] != b[0]) pasuxi.push_back(1);
    cout << pasuxi.size() << " ";
    for(int x : pasuxi) cout << x << " ";
    cout << endl;
}

int main()
{
    int t;
    cin >> t;
    while(t--) solve();
}


#include <bits/stdc++.h>

using namespace std;

char swap(char c)
{
    return c == '0' ? '1' : '0';
}

void solve()
{
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<int> pasuxi;
    for(int i = n - 1; i > 0; i--)
    {
        if(a[i] == b[i]) continue;
        if(a[i] != a[0])
        {
            a[0] = swap(a[0]);
            pasuxi.push_back(1);
        }
        pasuxi.push_back(i + 1);
        string swapwith = "";
        for(int j = i; j >= 0; j--)
        {
            swapwith += swap(a[j]);
        }
        for(int j = 0; j < i; j++)
            a[j] = swapwith[j];
    }
    if(a[0] != b[0]) pasuxi.push_back(1);
    cout << pasuxi.size() << " ";
    for(int x : pasuxi) cout << x << " ";
    cout << endl;
}

int main()
{
    int t;
    cin >> t;
    while(t--) solve();
}


#include <bits/stdc++.h>

using namespace std;

char swap(char c)
{
    return c == '0' ? '1' : '0';
}

void solve()
{
    int n;
    cin >> n;
    string sa, sb;
    cin >> sa >> sb;
    bool a[n], b[n];
    for(int i = 0; i < n; i++)
    {
        a[i] = sa[i] == '1';
        b[i] = sb[i] == '1';
    }
    vector<int> pasuxi;
    bool bit = a[0];
    for(int i = 1; i < n; i++)
    {
        if(a[i] != bit)
        {
            pasuxi.push_back(i);
            bit = !bit;
        }
    }
    if(bit) pasuxi.push_back(n);
    vector<int> bpasuxi;
    bit = b[0];
    for(int i = 1; i < n; i++)
    {
        if(b[i] != bit)
        {
            bpasuxi.push_back(i);
            bit = !bit;
        }
    }
    if(bit) bpasuxi.push_back(n);
    int size = pasuxi.size() + bpasuxi.size();
    cout << size << " ";
    for(int x : pasuxi) cout << x << " ";
    reverse(bpasuxi.begin(), bpasuxi.end());
    for(int x : bpasuxi) cout << x << " ";
    cout << endl;
}

int main()
{
    int t;
    cin >> t;
    while(t--) solve();
}


#include <bits/stdc++.h>

using namespace std;

char swap(char c)
{
    return c == '0' ? '1' : '0';
}

void solve()
{
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<int> pasuxi;
    //string swapwith = a;
    for(int i = n - 1; i > 0; i--)
    {
        if(a[i] == b[i]) continue;
        if(a[i] != a[0])
        {
            a[0] = swap(a[0]);
            pasuxi.push_back(1);
        }
        pasuxi.push_back(i + 1);
        //string swapwith = "";
        /*
        for(int j = i; j >= 0; j--)
        {
            swapwith[i - j] = swap(a[j]);
        }
        for(int j = 0; j < i; j++)
            a[j] = swapwith[j];
            */
        for(int j = 0; j <= i / 2; j++)
        {
            char old = swap(a[j]);
            a[j] = swap(a[i - j]);
            a[i - j] = old;
        }
    }
    if(a[0] != b[0]) pasuxi.push_back(1);
    cout << pasuxi.size() << " ";
    for(int x : pasuxi) cout << x << " ";
    cout << endl;
}

int main()
{
    int t;
    cin >> t;
    while(t--) solve();
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<ctime>
#define ll long long
#define gc getchar()
#define I inline
using namespace std;
const int mod=1e9+7,N=1e5+5;
template<class o>void qr(o &x)
{
	x=0;int f=1;char c=gc;while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc;}
	while(c>='0'&&c<='9'){x=x*10+(c^48);c=gc;}x*=f;
}
template<class o>void qw(o &x)
{
	if(x<0)x=-x,putchar('-');
	if(x/10)qw(x/10);putchar(x%10+48);
}
// math
I int ksm(int a,int b=mod-2){int ans=1;for(;b;b>>=1,a=1ll*a*a%mod)if(b&1)ans=1ll*ans*a%mod;return ans;}
int gcd(int a,int b){return !b?a:gcd(b,a%b);}
int exgcd(int a,int b,int &x,int &y){if(!b){x=1;y=0;return a;}int d=exgcd(b,a%b,y,x);y-=(a/b)*x;return d;}
int n,top,sta[N];
char a[N],b[N];
struct node{int x,nxt,prv;}e[N],emp;
int main()
{
	int t;qr(t);
	while(t--)
	{
		qr(n);top=0;
		scanf("%s%s",a+1,b+1);
		for(int i=1;i<=n;i++)e[i]=emp;
		e[0]=e[n+1]=emp;
		for(int i=1;i<=n;i++)
			e[i].x=a[i]-'0',e[i].nxt=i+1,e[i].prv=i-1;
		node st=e[1],ed=e[n];
		int w=0;
		for(int i=n;i;i--)
		if((ed.x^w)==b[i]-'0')
		{
			if(i==1)continue;
			if(!ed.nxt)ed=e[ed.prv],ed.nxt=0;
			else ed=e[ed.nxt],ed.prv=0;
		}
		else
		{
			if((st.x^w)==b[i]-'0')sta[++top]=1,st.x^=1;
			sta[++top]=i;swap(st,ed);w^=1;
			if(i==1)continue;
			if(!ed.nxt)ed=e[ed.prv],ed.nxt=0;
			else ed=e[ed.nxt],ed.prv=0;
		}
		printf("%d ",top);
		for(int i=1;i<=top;i++)printf("%d ",sta[i]);puts("");
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<ctime>
#define ll long long
#define gc getchar()
#define I inline
using namespace std;
const int mod=1e9+7,N=1e5+5;
template<class o>void qr(o &x)
{
	x=0;int f=1;char c=gc;while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc;}
	while(c>='0'&&c<='9'){x=x*10+(c^48);c=gc;}x*=f;
}
template<class o>void qw(o &x)
{
	if(x<0)x=-x,putchar('-');
	if(x/10)qw(x/10);putchar(x%10+48);
}
// math
I int ksm(int a,int b=mod-2){int ans=1;for(;b;b>>=1,a=1ll*a*a%mod)if(b&1)ans=1ll*ans*a%mod;return ans;}
int gcd(int a,int b){return !b?a:gcd(b,a%b);}
int exgcd(int a,int b,int &x,int &y){if(!b){x=1;y=0;return a;}int d=exgcd(b,a%b,y,x);y-=(a/b)*x;return d;}
int n,top,sta[N];
char a[N],b[N];
struct point{int x;point *nxt,*prv;}*e[N];
int main()
{
	int t;qr(t);
	while(t--)
	{
		qr(n);top=0;
		scanf("%s%s",a+1,b+1);
		for(int i=1;i<=n;i++)e[i]=new point();
		e[0]=e[n+1]=NULL;
		for(int i=1;i<=n;i++)
			e[i]->x=a[i]-'0',e[i]->nxt=e[i+1],e[i]->prv=e[i-1];
		point *l=e[1],*r=e[n];
		int w=0;
		for(int i=n;i;i--)
		if((r->x^w)==b[i]-'0')
		{
			if(i==1)continue;
			if(!r->nxt)r=r->prv,r->nxt=NULL;
			else r=r->nxt,r->prv=NULL;
		}
		else
		{
			if((l->x^w)==b[i]-'0')sta[++top]=1,l->x^=1;
			sta[++top]=i;swap(l,r);w^=1;
			if(i==1)continue;
			if(!r->nxt)r=r->prv,r->nxt=NULL;
			else r=r->nxt,r->prv=NULL;
		}
		printf("%d ",top);
		for(int i=1;i<=top;i++)printf("%d ",sta[i]);puts("");
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<ctime>
#define ll long long
#define gc getchar()
#define I inline
using namespace std;
const int mod=1e9+7,N=2e5+5;
template<class o>void qr(o &x)
{
	x=0;int f=1;char c=gc;while(c<'0'||c>'9'){if(c=='-')f=-1;c=gc;}
	while(c>='0'&&c<='9'){x=x*10+(c^48);c=gc;}x*=f;
}
template<class o>void qw(o &x)
{
	if(x<0)x=-x,putchar('-');
	if(x/10)qw(x/10);putchar(x%10+48);
}
// math
I int ksm(int a,int b=mod-2){int ans=1;for(;b;b>>=1,a=1ll*a*a%mod)if(b&1)ans=1ll*ans*a%mod;return ans;}
int gcd(int a,int b){return !b?a:gcd(b,a%b);}
int exgcd(int a,int b,int &x,int &y){if(!b){x=1;y=0;return a;}int d=exgcd(b,a%b,y,x);y-=(a/b)*x;return d;}
int n,top,sta[N];
char a[N],b[N];
struct point{int x;point *nxt,*prv;}*e[N];
int main()
{
	int t;qr(t);
	while(t--)
	{
		qr(n);top=0;
		scanf("%s%s",a+1,b+1);
		for(int i=1;i<=n;i++)e[i]=new point();
		e[0]=e[n+1]=NULL;
		for(int i=1;i<=n;i++)
			e[i]->x=a[i]-'0',e[i]->nxt=e[i+1],e[i]->prv=e[i-1];
		point *l=e[1],*r=e[n];
		int w=0;
		for(int i=n;i;i--)
		if((r->x^w)==b[i]-'0')
		{
			if(i==1)continue;
			if(!r->nxt)r=r->prv,r->nxt=NULL;
			else r=r->nxt,r->prv=NULL;
		}
		else
		{
			if((l->x^w)==b[i]-'0')sta[++top]=1,l->x^=1;
			sta[++top]=i;swap(l,r);w^=1;
			if(i==1)continue;
			if(!r->nxt)r=r->prv,r->nxt=NULL;
			else r=r->nxt,r->prv=NULL;
		}
		printf("%d ",top);
		for(int i=1;i<=top;i++)printf("%d ",sta[i]);puts("");
	}
	return 0;
}


#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iterator>
#include<math.h>
#define debug() puts("what the fuck")
#define ll long long
#define INF 0x3f3f3f3f
#define inf  0x3ffffffffffff
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int  maxn=8000009;
const double pi = acos(-1.0);
const int N=40010;
using namespace std;
vector<int>v;
void solve()
{
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    v.clear();
    for(int i=0; i<n; i++)
    {
        if(a[i]!=b[i])
        {
            v.push_back(i+1);
            v.push_back(1);
            v.push_back(i+1);
        }
    }
    cout<<v.size();
    for(vector<int> ::iterator it=v.begin(); it!=v.end(); it++)
        cout<<" "<<*it;
    cout<<endl;

}
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iterator>
#include<math.h>
#define debug() puts("what the fuck")
#define ll long long
#define INF 0x3f3f3f3f
#define inf  0x3ffffffffffff
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int  maxn=8000009;
const double pi = acos(-1.0);
const int N=40010;
using namespace std;
vector<int>av,bv;
void solve()
{
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    a.push_back('0');
    b.push_back('0');
    for(int k=1;k<=n;k++)
    {
        if(a[k]!=a[k-1])
            av.push_back(k);
         if(b[k]!=b[k-1])
            bv.push_back(k);
    }
    int l=av.size()+bv.size();
    cout<<l;
    for(vector<int>::iterator it=av.begin();it!=av.end();it++)
        cout<<" "<<*it;
         for(vector<int>::iterator it=bv.rbegin();it!=bv.rend();it++)
        cout<<" "<<*it;
        cout<<endl;
}
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iterator>
#include<math.h>
#define debug() puts("what the fuck")
#define ll long long
#define INF 0x3f3f3f3f
#define inf  0x3ffffffffffff
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int  maxn=8000009;
const double pi = acos(-1.0);
const int N=40010;
using namespace std;
vector<int>av,bv;
void solve()
{
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    a.push_back('0');
    b.push_back('0');
    av.clear();           //��������һ��Ҫ�ǵ����㣬��Ȼ����
    bv.clear();
    for(int k=1; k<=n; k++)
    {
        if(a[k]!=a[k-1])
            av.push_back(k);
        if(b[k]!=b[k-1])
            bv.push_back(k);
    }
    int l=av.size()+bv.size();
    cout<<l;
    for(auto it=av.begin(); it!=av.end(); it++)
        cout<<" "<<*it;
    for(auto it=bv.rbegin(); it!=bv.rend(); it++)
        cout<<" "<<*it;
    cout<<endl;
}
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iterator>
#include<math.h>
#define debug() puts("what the fuck")
#define ll long long
#define INF 0x3f3f3f3f
#define inf  0x3ffffffffffff
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int  maxn=8000009;
const double pi = acos(-1.0);
const int N=40010;
using namespace std;
vector<int>av,bv;
void solve()
{
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    a.push_back('0');
    b.push_back('0');
    for(int k=1;k<=n;k++)
    {
        if(a[k]!=a[k-1])
            av.push_back(k);
         if(b[k]!=b[k-1])
            bv.push_back(k);
    }
    int l=av.size()+bv.size();
    cout<<l;
    for(vector<int>::iterator it=av.begin();it!=av.end();it++)
        cout<<" "<<*it;
         for(auto it=bv.rbegin();it!=bv.rend();it++)
        cout<<" "<<*it;
        cout<<endl;
}
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iterator>
#include<math.h>
#define debug() puts("what the fuck")
#define ll long long
#define INF 0x3f3f3f3f
#define inf  0x3ffffffffffff
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int  maxn=8000009;
const double pi = acos(-1.0);
const int N=40010;
using namespace std;
vector<int>av,bv;
void solve()
{
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    a.push_back('0');
    b.push_back('0');
    for(int k=1;k<=n;k++)
    {
        if(a[k]!=a[k-1])
            av.push_back(k);
         if(b[k]!=b[k-1])
            bv.push_back(k);
    }
    int l=av.size()+bv.size();
    cout<<l;
    for(vector<int>::iterator it=av.begin();it!=av.end();it++)
        cout<<" "<<*it;
         for(vector<int>::iterator it=bv.begin();it!=bv.end();it++)
        cout<<" "<<*it;
        cout<<endl;
}
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iterator>
#include<math.h>
#define debug() puts("what the fuck")
#define ll long long
#define INF 0x3f3f3f3f
#define inf  0x3ffffffffffff
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int  maxn=8000009;
const double pi = acos(-1.0);
const int N=40010;
using namespace std;
vector<int>av,bv;
void solve()
{
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;
    a.push_back('0');
    b.push_back('0');
    av.clear();
    bv.clear();
    for(int k=1;k<=n;k++)
    {
        if(a[k]!=a[k-1])
            av.push_back(k);
         if(b[k]!=b[k-1])
            bv.push_back(k);
    }
    int l=av.size()+bv.size();
    cout<<l;
    for(auto it=av.begin();it!=av.end();it++)
        cout<<" "<<*it;
         for(auto it=bv.rbegin();it!=bv.rend();it++)
        cout<<" "<<*it;
        cout<<endl;
}
int main()
{
    ll t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 100010;
string a,b;
vector<int>v1,v2;
int main(){
	int T;
	int n;
	cin>>T;
	while(T--){
		v1.clear();
		v2.clear();
		cin>>n;
		cin>>a>>b;
		if(a==b){
			cout<<0<<endl;
			continue;
		}
		int a0=a[0]-'0';
		int b0=b[0]-'0';
		for(int i=0;i<n-1;i++){
			if(a[i]!=a[i+1]){
				v1.push_back(i+1);
				if(!i)a0=(a0==1)?0:1;
			}
			if(b[i]!=b[i+1]){
				v2.push_back(i+1);
				if(!i)b0=(b0)?0:1;
			}
		}
		if(a0!=b0)v2.push_back(n);
			cout<<v1.size()+v2.size()<<" ";
			for(auto t:v1)cout<<t<<" ";
			reverse(v2.begin(),v2.end());
			for(auto t:v2)cout<<t<<" ";
			cout<<endl;
	}
}


#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 100010;
string a,b;
vector<int>v1,v2;
int main(){
	int T;
	int n;
	cin>>T;
	while(T--){
		v1.clear();
		v2.clear();
		cin>>n;
		cin>>a>>b;
		if(a==b){
			cout<<0<<endl;
			continue;
		}
		int a0=a[0]-'0';
		int b0=b[0]-'0';
		for(int i=0;i<n-1;i++){
			if(a[i]!=a[i+1]){
				v1.push_back(i+1);
				a0=(a[i]-'0')?0:1;
			}
			if(b[i]!=b[i+1]){
				v2.push_back(i+1);
				b0=(b[i]-'0')?0:1;
			}
		}
		if(a0!=b0)v1.push_back(n);
			cout<<v1.size()+v2.size()<<" ";
			if(v1.size()!=0)
				for(auto t:v1)cout<<t<<" ";
			reverse(v2.begin(),v2.end());
			if(v2.size()!=0)
				for(auto t:v2)cout<<t<<" ";
			cout<<endl;
	}
}


#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 100010;
string a,b;
vector<int>v1,v2;
int main(){
	int T;
	int n;
	cin>>T;
	while(T--){
		v1.clear();
		v2.clear();
		cin>>n;
		cin>>a>>b;
		for(int i=0;i<n-1;i++){
			if(a[i]!=a[i+1])v1.push_back(i+1);
			if(b[i]!=b[i+1])v2.push_back(i+1);
		}
		if(b[0]!=a[0])v2.push_back(n);
		if(a==b)cout<<0<<endl;
		else{
			cout<<v1.size()+v2.size()<<" ";
			for(auto t:v1)cout<<t<<" ";
			reverse(v2.begin(),v2.end());
			for(auto t:v2)cout<<t<<" ";
			cout<<endl;
		}

	}
}


#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 100010;
string a,b;
vector<int>v1,v2;
int main(){
	int T;
	int n;
	cin>>T;
	while(T--){
		v1.clear();
		v2.clear();
		cin>>n;
		cin>>a>>b;
		for(int i=0;i<n-1;i++){
			if(a[i]!=a[i+1])v1.push_back(i+1);
			if(b[i]!=b[i+1])v2.push_back(i+1);
		}
		if(b[0]!=a[0])v2.push_back(n);
		cout<<v1.size()+v2.size()<<" ";
		for(auto t:v1)cout<<t<<" ";
		reverse(v2.begin(),v2.end());
		for(auto t:v2)cout<<t<<" ";
		cout<<endl;
	}
}


#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 100010;
string a,b;
vector<int>v1,v2;
int main(){
	int T;
	int n;
	cin>>T;
	while(T--){
		v1.clear();
		v2.clear();
		cin>>n;
		cin>>a>>b;
		if(a==b){
			cout<<0<<endl;
			continue;
		}
		int a0=a[0]-'0';
		int b0=b[0]-'0';
		for(int i=0;i<n-1;i++){
			if(a[i]!=a[i+1]){
				v1.push_back(i+1);
				if(!i)a0=(a0==1)?0:1;
			}
			if(b[i]!=b[i+1]){
				v2.push_back(i+1);
				if(!i)b0=(b0)?0:1;
			}
		}
		if(a0==1)v1.push_back(n);
		if(b0==1)v2.push_back(n);
			cout<<v1.size()+v2.size()<<" ";
			if(v1.size()!=0)
				for(auto t:v1)cout<<t<<" ";
			reverse(v2.begin(),v2.end());
			if(v2.size()!=0)
				for(auto t:v2)cout<<t<<" ";
			cout<<endl;
	}
}


#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 100010;
string a,b;
vector<int>v1,v2;
int main(){
	int T;
	int n;
	cin>>T;
	while(T--){
		v1.clear();
		v2.clear();
		cin>>n;
		cin>>a>>b;
		if(a==b){
			cout<<0<<endl;
			continue;
		}
		int a0=a[0]-'0';
		int b0=b[0]-'0';
		for(int i=0;i<n-1;i++){
			if(a[i]!=a[i+1]){
				v1.push_back(i+1);
//				if(!i)a0=(a0==1)?0:1;
			}
			if(b[i]!=b[i+1]){
				v2.push_back(i+1);
//				if(!i)b0=(b0)?0:1;
			}
		}
//		if(a0==1)v1.push_back(n);
//		if(b0==1)v2.push_back(n);
		if(a0!=b0)v1.push_back(n);
			cout<<v1.size()+v2.size()<<" ";
			if(v1.size()!=0)
				for(auto t:v1)cout<<t<<" ";
			reverse(v2.begin(),v2.end());
			if(v2.size()!=0)
				for(auto t:v2)cout<<t<<" ";
			cout<<endl;
	}
}


#include<bits/stdc++.h>
typedef long long int ll;
#define vi vector<ll>
#define pi pair<ll,ll>
#define pb push_back
using namespace std;

vi flip(vi a, int last){
    int n  = a.size();
    vi b(n),c(n);
    for(int i = 0; i < a.size(); i++){
        if( i <=last){
            b[last-i] = a[i] == 0 ? 1 : 0;
        }
        else{
            b[i] = a[i];
        }

    }
    return b;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s1,s2;
        cin>>s1>>s2;
        vi a(n),b(n),c(n),d(n);
        for(int i = 0; i < n; i++){
            a[i] = (s1[i]-'0');
        }
        for(int i = 0; i < n; i++){
            b[i] = (s2[i]-'0');
        }
        vi res;
        for(int i = 0; i<n-1; i++){
            if(a[i] != a[i+1]){
                //a = flip(a,i);
                res.pb(i+1);
            }
        }
        if(a[0]==1){
            //a = flip(a,n-1);
            res.pb(n);
        }
        vi res2;
        for(int i = 0; i<n-1; i++){
            if(b[i] != b[i+1]){
                //b = flip(b,i);
                res2.pb(i+1);
            }
        }
        if(b[0]==1){
            //b = flip(b,n-1);
            res2.pb(n);
        }
        for(int i = res2.size()-1; i>=0; i--){
            res.pb(res2[i]);
        }
        cout<<res.size()<<" ";
        for(int i = 0; i < res.size(); i++){
            cout<<res[i]<<" ";
        }
        cout<<"\n";
    }
    return 0;

}


#include<bits/stdc++.h>
typedef long long int ll;
#define vi vector<ll>
#define pi pair<ll,ll>
#define pb push_back
using namespace std;

vi flip(vi a, int last){
    int n  = a.size();
    vi b(n),c(n);
    for(int i = 0; i < a.size(); i++){
        if( i <=last){
            b[last-i] = a[i] == 0 ? 1 : 0;
        }
        else{
            b[i] = a[i];
        }

    }
    return b;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s1,s2;
        cin>>s1>>s2;
        vi a(n),b(n),c(n),d(n);
        for(int i = 0; i < n; i++){
            a[i] = (s1[i]-'0');
        }
        for(int i = 0; i < n; i++){
            b[i] = (s2[i]-'0');
        }
        vi res;
        for(int i = 0; i<n-1; i++){
            if(a[i] != a[i+1]){
                a = flip(a,i);
                res.pb(i+1);
            }
        }
        if(a[0]==1){
            a = flip(a,n-1);
            res.pb(n);
        }
        vi res2;
        for(int i = 0; i<n-1; i++){
            if(b[i] != b[i+1]){
                b = flip(b,i);
                res2.pb(i+1);
            }
        }
        if(b[0]==1){
            b = flip(b,n-1);
            res2.pb(n);
        }
        for(int i = res2.size()-1; i>=0; i--){
            res.pb(res2[i]);
        }
        cout<<res.size()<<" ";
        for(int i = 0; i < res.size(); i++){
            cout<<res[i]<<" ";
        }
        cout<<"\n";
    }
    return 0;

}


#include<bits/stdc++.h>
typedef long long int ll;
#define vi vector<ll>
#define pi pair<ll,ll>
#define pb push_back
using namespace std;

vi flip(vi a, int last){
    int n  = a.size();
    vi b(n),c(n);
    /*cout<<"Original: ";
    for(int i = 0; i < n; i++){
        cout<<a[i]<<" ";
    }
    cout<<"\n";*/

    for(int i = 0; i < a.size(); i++){
        if( i <=last){
            b[i] = a[i] == 0 ? 1 : 0;
            c[last-i] =b[i];
        }
        else{
            b[i] = a[i];
            c[i] = a[i];
        }

    }
    /*cout<<"volteado: ";
    for(int i = 0; i < n; i++){
        cout<<b[i]<<" ";
    }
    cout<<"\n";
    cout<<"rotado:   ";
    for(int i = 0; i < n; i++){
        cout<<c[i]<<" ";
    }
    cout<<"\n";*/
    return c;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s1,s2;
        cin>>s1>>s2;
        vi a(n),b(n),c(n),d(n);
        for(int i = 0; i < n; i++){
            a[i] = (s1[i]-'0');
            d[i] = a[i];
        }
        for(int i = 0; i < n; i++){
            b[i] = (s2[i]-'0');
            c[i] = b[i];
        }
        vi res;
        for(int i = 0; i<n-1; i++){
            if(a[i] != a[i+1]){
                a = flip(a,i);
                res.pb(i+1);
            }
        }
        if(a[0]==1){
            a = flip(a,n-1);
            res.pb(n);
        }
        vi res2;
        for(int i = 0; i<n-1; i++){
            if(b[i] != b[i+1]){
                b = flip(b,i);
                res2.pb(i+1);
            }
        }
        if(b[0]==1){
            b = flip(b,n-1);
            res2.pb(n);
        }
        for(int i = res2.size()-1; i>=0; i--){
            res.pb(res2[i]);
        }
        cout<<res.size()<<" ";
        for(int i = 0; i < res.size(); i++){
            cout<<res[i]<<" ";
        }
        cout<<"\n";
    }
    return 0;

}


#include<bits/stdc++.h>
typedef long long int ll;
#define vi vector<ll>
#define pi pair<ll,ll>
#define pb push_back
using namespace std;

vi flip(vi a, int last){
    int n  = a.size();
    vi b(n),c(n);
    for(int i = 0; i < a.size(); i++){
        if( i <=last){
            b[last-i] = a[i] == 0 ? 1 : 0;
        }
        else{
            b[i] = a[i];
        }

    }
    return b;
}

int main(){
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s1,s2;
        cin>>s1>>s2;
        vi a(n),b(n),c(n),d(n);
        for(int i = 0; i < n; i++){
            a[i] = (s1[i]-'0');
        }
        for(int i = 0; i < n; i++){
            b[i] = (s2[i]-'0');
        }
        vi res;
        for(int i = 0; i<n-1; i++){
            if(a[i] != a[i+1]){
                //a = flip(a,i);
                res.pb(i+1);
            }
        }
        if(a[n-1]==1){
            //a = flip(a,n-1);
            res.pb(n);
        }
        vi res2;
        for(int i = 0; i<n-1; i++){
            if(b[i] != b[i+1]){
                //b = flip(b,i);
                res2.pb(i+1);
            }
        }
        if(b[n-1]==1){
            //b = flip(b,n-1);
            res2.pb(n);
        }
        for(int i = res2.size()-1; i>=0; i--){
            res.pb(res2[i]);
        }
        cout<<res.size()<<" ";
        for(int i = 0; i < res.size(); i++){
            cout<<res[i]<<" ";
        }
        cout<<"\n";
    }
    return 0;

}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;

typedef long long int ll;

int main(void)
{
	ll t;
	cin >> t;

	while(t--)
	{
		// cout << "---------------------\n";
		ll n;
		string a,b;
		cin >> n;
		cin >> a >> b;

		// check for length == 1
		char elem = a[0];
		vector <ll> u;
		for(ll i=0;i<n-1;i++)
		{
			if(a[i] != a[i+1])
			{
				// cout << "vector u ,idx= " << i << endl;
				//flip pref a[0....i]
				elem = a[i+1];
				u.push_back(i+1);
			}
		}

		char fin = b[0];
		vector <ll> v;
		for(ll i=0;i<n-1;i++)
		{
			if(b[i] != b[i+1])
			{
				// cout << "vector v ,idx= " << i << endl;
				//flip pref b[0....i]
				fin = b[i+1];
				v.push_back(i+1);
			}
		}
		if(elem != fin)
			u.push_back(n);

		// cout << "u.size: " << u.size() << "  v.size: " << v.size() << endl;
		cout << u.size() + v.size() << " ";

		for(ll i=0; i<u.size(); i++)
			cout << u[i] << " ";
		for(ll i=v.size()-1; i>=0; i--)
			cout << v[i]<< " ";
		cout << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;

// typedef long long int ll;

long int t,n;
string a,b;

int main(void)
{
	cin >> t;

	while(t--)
	{
		cin >> n >> a >> b;

		// check for length == 1
		char elem = a[0];
		vector <long int> u;
		for(long int i=0;i<n-1;i++)
		{
			if(a[i] != a[i+1])
			{
				// cout << "vector u ,idx= " << i << endl;
				//flip pref a[0....i]
				elem = a[i+1];
				u.push_back(i+1);
			}
		}

		char fin = b[0];
		vector <long int> v;
		for(long int i=0;i<n-1;i++)
		{
			if(b[i] != b[i+1])
			{
				// cout << "vector v ,idx= " << i << endl;
				//flip pref b[0....i]
				fin = b[i+1];
				v.push_back(i+1);
			}
		}
		if(elem != fin)
			u.push_back(n);

		// cout << "u.size: " << u.size() << "  v.size: " << v.size() << endl;
		cout << u.size() + v.size() << " ";

		for(long int i=0; i<u.size(); i++)
			cout << u[i] << " ";
		for(long int i=v.size()-1; i>=0; i--)
			cout << v[i] << " ";
		cout << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;

typedef long long int ll;

int main(void)
{
	ll t;
	cin >> t;

	while(t--)
	{
		ll n;
		string a,b;
		cin >> n;
		cin >> a >> b;

		// check for length == 1
		char elem = a[0];
		vector <ll> u;
		for(ll i=0;i<n-1;i++)
		{
			if(a[i] != a[i+1])
			{
				// cout << "vector u ,idx= " << i << endl;
				//flip pref a[0....i]
				elem = a[i+1];
				u.push_back(i+1);
			}
		}

		char fin = b[0];
		vector <ll> v;
		for(ll i=0;i<n-1;i++)
		{
			if(b[i] != b[i+1])
			{
				// cout << "vector v ,idx= " << i << endl;
				//flip pref b[0....i]
				fin = b[i+1];
				v.push_back(i+1);
			}
		}
		if(elem != fin)
			u.push_back(n);

		// cout << "u.size: " << u.size() << "  v.size: " << v.size() << endl;
		cout << u.size() + v.size() << " ";

		for(ll i=0; i<u.size(); i++)
			cout << u[i] << " ";
		for(ll i=v.size()-1; i>=0; i--)
			cout << v[i]<< " ";
		cout << endl;
	}

	return 0;
}


    #include <bits/stdc++.h>
    using namespace std;

    // Solution 1 from editorial
    // Credit: The testers Kuroni and SecondThread independently came up with this elegant solution,
    //     while solution 2 from editorial was intended.
    // We convert a -> 0000000 -> b
    // to convert a string to 0000000, we make prefix 2 all same bit, then prefix 3 all same bit, etc.
    // to convert 0000000 -> b, we convert b -> 0000000 and reverse the order of operations.

    int t, n;
    string a, b;

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


#include<bits/stdc++.h>
#include<iostream>
using namespace std;

// typedef long long int ll;

long long int t,n;
string a,b;

int main(void)
{
	cin >> t;

	while(t--)
	{
		cin >> n >> a >> b;

		// check for length == 1
		char elem = a[0];
		vector <long long int> u;
		for(long long int i=0;i<n-1;i++)
		{
			if(a[i] != a[i+1])
			{
				// cout << "vector u ,idx= " << i << endl;
				//flip pref a[0....i]
				elem = a[i+1];
				u.push_back(i+1);
			}
		}

		char fin = b[0];
		vector <long long int> v;
		for(long long int i=0;i<n-1;i++)
		{
			if(b[i] != b[i+1])
			{
				// cout << "vector v ,idx= " << i << endl;
				//flip pref b[0....i]
				fin = b[i+1];
				v.push_back(i+1);
			}
		}
		if(elem != fin)
			u.push_back(n);

		// cout << "u.size: " << u.size() << "  v.size: " << v.size() << endl;
		cout << u.size() + v.size() << " ";

		for(long long int i=0; i<u.size(); i++)
			cout << u[i] << " ";
		for(long long int i=v.size()-1; i>=0; i--)
			cout << v[i] << " ";
		cout << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
#include<iostream>
using namespace std;

// typedef long long int ll;

int t,n;
string a,b;

int main(void)
{
	cin >> t;

	while(t--)
	{
		cin >> n >> a >> b;

		// check for length == 1
		char elem = a[0];
		vector <int> u;
		for(int i=0;i<n-1;i++)
		{
			if(a[i] != a[i+1])
			{
				// cout << "vector u ,idx= " << i << endl;
				//flip pref a[0....i]
				elem = a[i+1];
				u.push_back(i+1);
			}
		}

		char fin = b[0];
		vector <int> v;
		for(int i=0;i<n-1;i++)
		{
			if(b[i] != b[i+1])
			{
				// cout << "vector v ,idx= " << i << endl;
				//flip pref b[0....i]
				fin = b[i+1];
				v.push_back(i+1);
			}
		}
		if(elem != fin)
			u.push_back(n);

		// cout << "u.size: " << u.size() << "  v.size: " << v.size() << endl;
		cout << u.size() + v.size() << " ";

		for(int i=0; i<u.size(); i++)
			cout << u[i] << " ";
		for(int i=v.size()-1; i>=0; i--)
			cout << v[i] << " ";
		cout << endl;
	}

	return 0;
}


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

string f(string str) {
	// cout << str << endl;
	string ret = "";
	for(int i=str.size()-1;i>=0;i--) {
		if(str[i] == '1') ret.push_back('0');
		else ret.push_back('1');
	}
	return ret;
}

int main() {
	int tc; cin >> tc;
	while(tc--) {
		int n; scanf("%d", &n);
		vector<int> v;
		string a, b;
		cin >> a >> b;

		int cnt = 0;

		int idx = n - 1;
		while(idx >= 1) {
			if(a[idx] != b[idx]) {
				if(a[0] == b[idx]) {
					v.push_back(1);
					cnt++;
					if(a[0] == '1') a[0] = '0';
					else a[0] = '1';
				}

				a = f(a);
				v.push_back(idx + 1);
				cnt++;
			}
			a.pop_back();
			// cout << a << endl;
			idx--;
		}

		if(a[0] != b[0]) {
			v.push_back(1);
			cnt++;
		}

		printf("%d ", cnt);
		for(int i : v) {
			printf("%d ", i);
		}
		puts("");
	}
}


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

string f(string str) {
	// cout << str << endl;
	string ret = "";
	for(int i=str.size()-1;i>=0;i--) {
		if(str[i] == '1') ret.push_back('0');
		else ret.push_back('1');
	}
	return ret;
}

int main() {
	int tc; cin >> tc;
	while(tc--) {
		int n; scanf("%d", &n);
		vector<int> v;
		string a, b;
		cin >> a >> b;

		int cnt = 0;

		int idx = n - 1;
		while(idx >= 1) {
			if(a[idx] != b[idx]) {
				if(a[0] == b[idx]) {
					v.push_back(1);
					cnt++;
					if(a[0] == '1') a[0] = '0';
					else a[0] = '1';
				}

				a = f(a.substr(0, idx + 1)) + a.substr(idx);
				v.push_back(idx + 1);
				cnt++;
			}
			// cout << a << endl;
			idx--;
		}

		if(a[0] != b[0]) {
			v.push_back(1);
			cnt++;
		}

		printf("%d ", cnt);
		for(int i : v) {
			printf("%d ", i);
		}
		puts("");
	}
}


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

int main() {
	int tc; cin >> tc;
	while(tc--) {
		int n; scanf("%d", &n);
		string a, b;
		cin >> a >> b;

		vector<int> v;
		for(int i=0;i<n-1;i++) {
			if(a[i] != a[i+1]) {
				v.push_back(i+1);
			}
		}
		if(a[n-1] == '1') {
			v.push_back(n);
		}

		bool isOne = false;
		for(int i=n-1;i>=0;i--) {
			if(b[i] == '1' && !isOne) {
				v.push_back(i+1);
				isOne = !isOne;
			} else if(b[i] == '0' && isOne) {
				v.push_back(i+1);
				isOne = !isOne;
			}
		}

		printf("%d ", v.size());
		for(int i : v) {
			printf("%d ", i);
		}
		puts("");
	}
}


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

int main() {
	int tc; cin >> tc;
	while(tc--) {
		int n; scanf("%d", &n);
		string a, b;
		cin >> a >> b;

		vector<int> v;
		for(int i=0;i<n-1;i++) {
			if(a[i] != a[i+1]) {
				v.push_back(i);
			}
		}
		if(a[n-1] == '1') {
			v.push_back(n);
		}

		bool isOne = false;
		for(int i=n-1;i>=0;i--) {
			if(b[i] == '1' && !isOne) {
				v.push_back(i+1);
				isOne = !isOne;
			} else if(b[i] == '0' && isOne) {
				v.push_back(i+1);
				isOne = !isOne;
			}
		}

		printf("%d ", v.size());
		for(int i : v) {
			printf("%d ", i);
		}
		puts("");
	}
}


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

string f(string str, int n) {
	string ret = "";
	for(int i=0;i<str.size();i++) {
		if(i <= n) {
			if(str[i] == '0') ret.push_back('1');
			else ret.push_back('0');
			if(i == n) reverse(ret.begin(), ret.end());
		} else {
			ret.push_back(str[i]);
		}
	}

	return ret;
}
int main() {
	int tc; cin >> tc;
	while(tc--) {
		int n; scanf("%d", &n);
		vector<int> v;
		string a, b;
		cin >> a >> b;

		int cnt = 0;

		int idx = n - 1;
		while(idx >= 1) {
			if(a[idx] != b[idx]) {
				if(a[0] == b[idx]) {
					v.push_back(1);
					cnt++;
					if(a[0] == '1') a[0] = '0';
					else a[0] = '1';
				}

				a = f(a, idx);
				v.push_back(idx + 1);
				cnt++;
			}
			// cout << a << endl;
			idx--;
		}

		if(a[0] != b[0]) {
			v.push_back(1);
			cnt++;
		}

		printf("%d ", cnt);
		for(int i : v) {
			printf("%d ", i);
		}
		puts("");
	}
}


#include <bits/stdc++.h>

using namespace std;

int t, n;
string a, b;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    while(t--) {
        cin >> n >> a >> b;
        bool flip = false;
        int idx = 0;
        vector<int> ops;
        for(int i = n - 1; i >= 0; i--) {
            if(flip ^ (a[idx] == b[i])) {
                ops.push_back(1);
            }
            ops.push_back(i + 1);
            if(flip) idx -= i;
            else idx += i;
            flip = !flip;
        }
        cout << ops.size() << ' ';
        for(int x : ops) {
            cout << x << ' ';
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

// Solution 1 from editorial
// Fix the bits one-by-one in forward order
// at most 3 operations per bit, and O(n) time complexity.

int t, n;
string a, b;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    while(t--) {
        cin >> n >> a >> b;
        vector<int> ops;
        for(int i = 0; i < n; i++) {
            if(a[i] != b[i]) {
                if(i > 0) ops.push_back(i + 1);
                ops.push_back(1);
                if(i > 0) ops.push_back(i + 1);
            }
        }
        cout << ops.size() << ' ';
        for(int x : ops) {
            cout << x << ' ';
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;
int t, n, a[N];

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

// #include<bits/stdc++.h>

// using namespace std;

// typedef long long ll;
// int const maxn = 2005;
// char a[maxn][maxn];
// int cnt_up[maxn][maxn], cnt_down[maxn][maxn], L[maxn], R[maxn];

// main() {
//     ios_base::sync_with_stdio(0);
//     cin.tie(0);
//     cout.tie(0);
//     int n, m;
//     cin >> n >> m;
//     for (int i = 1; i <= n; ++i) {
//         for (int j = 1; j <= m; ++j) cin >> a[i][j];
//     }
//     ll ans = 0;
//     for (int i = 1; i <= n; ++i) {
//         for (int j = 1; j <= m; ++j) {
//             if (i != 1 && a[i][j] == a[i - 1][j]) cnt_up[i][j] = cnt_up[i - 1][j] + 1;
//             else cnt_up[i][j] = 0;
//         }
//     }
//     for (int i = n; i >= 1; --i) {
//         for (int j = 1; j <= m; ++j) {
//             if (i != n && a[i][j] == a[i + 1][j]) cnt_down[i][j] = cnt_down[i + 1][j] + 1;
//             else cnt_down[i][j] = 0;
//         }
//     }
//     for (int i = 1; i <= n; ++i) {
//         for (int j = 1; j <= m; ++j) {
//             int go = j;
//             while (go <= m && a[i][j] == a[i][go]) go++;
//             go--;
//             for (int pos = j; pos <= go; ++pos) {
//                 if (pos == j) L[pos] = pos;
//                 else {
//                    L[pos] = max(L[pos - 1], pos - min(cnt_up[i][pos], cnt_down[i][pos]));
//                 }
//             }
//             j = go;
//         }
//         for (int j = m; j >= 1; --j) {
//             int go = j;
//             while (go >= 1 && a[i][j] == a[i][go]) go--;
//             go++;
//             for (int pos = j; pos >= go; --pos) {
//                 if (pos == j) R[pos] = pos;
//                 else {
//                    R[pos] = min(R[pos + 1], pos + min(cnt_up[i][pos], cnt_down[i][pos]));
//                 }
//             }
//             j = go;
//         }
//         for (int j = 1; j <= m; ++j) {
//             ans += (ll)min(j - L[j] + 1, R[j] - j + 1);
//         }
//     }
//     cout << ans << '\n';
//     return 0;
// }


#include <bits/stdc++.h>

using namespace std;

#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;
int t, n, a[N];

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

// #include<bits/stdc++.h>

// using namespace std;

// typedef long long ll;
// int const maxn = 2005;
// char a[maxn][maxn];
// int cnt_up[maxn][maxn], cnt_down[maxn][maxn], L[maxn], R[maxn];

// main() {
//     ios_base::sync_with_stdio(0);
//     cin.tie(0);
//     cout.tie(0);
//     int n, m;
//     cin >> n >> m;
//     for (int i = 1; i <= n; ++i) {
//         for (int j = 1; j <= m; ++j) cin >> a[i][j];
//     }
//     ll ans = 0;
//     for (int i = 1; i <= n; ++i) {
//         for (int j = 1; j <= m; ++j) {
//             if (i != 1 && a[i][j] == a[i - 1][j]) cnt_up[i][j] = cnt_up[i - 1][j] + 1;
//             else cnt_up[i][j] = 0;
//         }
//     }
//     for (int i = n; i >= 1; --i) {
//         for (int j = 1; j <= m; ++j) {
//             if (i != n && a[i][j] == a[i + 1][j]) cnt_down[i][j] = cnt_down[i + 1][j] + 1;
//             else cnt_down[i][j] = 0;
//         }
//     }
//     for (int i = 1; i <= n; ++i) {
//         for (int j = 1; j <= m; ++j) {
//             int go = j;
//             while (go <= m && a[i][j] == a[i][go]) go++;
//             go--;
//             for (int pos = j; pos <= go; ++pos) {
//                 if (pos == j) L[pos] = pos;
//                 else {
//                    L[pos] = max(L[pos - 1], pos - min(cnt_up[i][pos], cnt_down[i][pos]));
//                 }
//             }
//             j = go;
//         }
//         for (int j = m; j >= 1; --j) {
//             int go = j;
//             while (go >= 1 && a[i][j] == a[i][go]) go--;
//             go++;
//             for (int pos = j; pos >= go; --pos) {
//                 if (pos == j) R[pos] = pos;
//                 else {
//                    R[pos] = min(R[pos + 1], pos + min(cnt_up[i][pos], cnt_down[i][pos]));
//                 }
//             }
//             j = go;
//         }
//         for (int j = 1; j <= m; ++j) {
//             ans += (ll)min(j - L[j] + 1, R[j] - j + 1);
//         }
//     }
//     cout << ans << '\n';
//     return 0;
// }


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int tc,n;
string str;

int main(){
	cin>>tc;
	while(tc--){
		vector <int> v;
		string a,b,c;
		cin>>n;
		cin>>a>>b;
		for(int i=0;i<n/2;i++){
			c+=a[i];
			c+=a[n-i-1];
		}
		if(n%2==1) c+=a[n/2];
		for(int i=0;i<n;i++){
			if(c[i]!=b[n-i-1]){
				v.push_back(n-i-1);
			}
			else{
				v.push_back(0);
				v.push_back(n-i-1);
			}
		}
		cout<<v.size()<<" ";
		for(int i=0;i<v.size();i++){
			cout<<v[i]+1<<" ";
		}
		cout<<'\n';
		v.clear();
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int tc,n;
string str;

int main(){
	cin>>tc;
	while(tc--){
		vector <int> v;
		string a,b,c;
		cin>>n;
		cin>>a>>b;
		for(int i=0;i<n/2;i++){
			c+=a[i];
			if(a[n-i-1]=='1') c+='0';
			else c+='1';
		}
//		cout<<"c "<<c<<'\n';
		if(n%2==1) c+=a[n/2];
		for(int i=0;i<n;i++){
			if(c[i]!=b[n-i-1]){
				v.push_back(n-i-1);
			}
			else if(c[i]==b[n-i-1]){
				v.push_back(0);
				if(i!=n-1)v.push_back(n-i-1);
			}
		}
		cout<<v.size()<<" ";
		for(int i=0;i<v.size();i++){
			cout<<v[i]+1<<" ";
		}
		cout<<'\n';
		v.clear();
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int tc,n;
string str;

int main(){
	cin>>tc;
	while(tc--){
		vector <int> v;
		string a,b;
		string c="";
		cin>>n;
		cin>>a>>b;
		if(a==b){
			cout<<0<<'\n';
			goto here;
		}
		for(int i=0;i<n/2;i++){
			c+=a[i];
			if(a[n-i-1]=='1') c+='0';
			else c+='1';
		}
//		cout<<"c "<<c<<'\n';
		if(n%2==1) c+=a[n/2];
		for(int i=0;i<n;i++){
			if(c[i]!=b[n-i-1]){
				v.push_back(n-i-1);
			}
			else if(c[i]==b[n-i-1]){
				v.push_back(0);
				if(i!=n-1)v.push_back(n-i-1);
			}
		}
		cout<<v.size()<<" ";
		for(int i=0;i<v.size();i++){
			cout<<v[i]+1<<" ";
		}
		cout<<'\n';
		v.clear();
		here:;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int tc,n;
string str;

int main(){
	cin>>tc;
	while(tc--){
		vector <int> v;
		string a,b;
		string c="";
		cin>>n;
		cin>>a>>b;
		if(a==b){
			cout<<0<<'\n';
			goto here;
		}
		for(int i=0;i<n/2;i++){
			c+=a[i];
			if(a[n-i-1]=='1') c+='0';
			else c+='1';
		}
//		cout<<"c "<<c<<'\n';
		if(n%2==1) c+=a[n/2];
		for(int i=0;i<n;i++){
			if(c[i]!=b[n-i-1]){
				v.push_back(n-i-1);
			}
			else if(c[i]==b[n-i-1]){
				v.push_back(0);
				v.push_back(n-i-1);
			}
		}
		cout<<v.size()<<" ";
		for(int i=0;i<v.size();i++){
			cout<<v[i]+1<<" ";
		}
		cout<<'\n';
		v.clear();
		here:;
	}
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int tc,n;
string str;

int main(){
	cin>>tc;
	while(tc--){
		vector <int> v;
		string a,b,c;
		cin>>n;
		cin>>a>>b;
		for(int i=0;i<n/2;i++){
			c+=a[i];
			c+=a[n-i-1];
		}
//		cout<<"c "<<c<<'\n';
		if(n%2==1) c+=a[n/2];
		for(int i=0;i<n;i++){
			if(c[i]!=b[n-i-1]){
				v.push_back(n-i-1);
			}
			else if(c[i]==b[n-i-1]){
				v.push_back(0);
				if(i!=n-1)v.push_back(n-i-1);
			}
		}
		cout<<v.size()<<" ";
		for(int i=0;i<v.size();i++){
			cout<<v[i]+1<<" ";
		}
		cout<<'\n';
		v.clear();
	}
}


#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 2e9;
const ll mod = 1e9 + 7;
const int N = 1e6 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);

ifstream in(".in");
ofstream out(".out");

int n, m;// a[N];
string a, b;

void solve(){

    cin >> n;

    cin >> a >> b;

    vector<int>v1,v2;

    a += '0';
    b += '0';

    for(int i = 1; i <= n; i++){
        if(a[i] != a[i - 1])v1.pb(i);
        if(b[i] != b[i - 1])v2.pb(i);
    }

    reverse(all(v2));
    cout << sz(v1) + sz(v2) << '\n';
    for(auto it : v1)cout << it << ' ';
    for(auto it : v2)cout << it << ' ';
    cout << '\n';
}

int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

   // cout << setprecision(6) << fixed;

    int T = 1;
    cin >> T;
    while(T--){
        solve();
    }
}


#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 2e9;
const ll mod = 1e9 + 7;
const int N = 1e6 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);

ifstream in(".in");
ofstream out(".out");

int n, m, a[N];

void solve(){

	cin >> n;

    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }

    int bl = 0, pos = 1;

    while(pos <= n && a[pos] == 1){
        bl = 1 - bl;
        pos++;
    }

    if(pos == n + 1){
        cout << (bl == 1 ? "First" : "Second") << '\n';
        return;
    }

    cout << (bl == 0 ? "First" : "Second") << '\n';

}

int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

   // cout << setprecision(6) << fixed;

    int T = 1;
    cin >> T;
    while(T--){
        solve();
    }
}


#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 2e9;
const ll mod = 1e9 + 7;
const int N = 1e6 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);

ifstream in(".in");
ofstream out(".out");

int n, m;// a[N];
string a, b;

string rev(string s){
    string ans = "";
    for(int i = sz(s) - 1; i >= 0; i--){
        int x = 1 - (s[i] - '0');
        ans += (x + '0');
    }
    return ans;
}

void solve(){

    cin >> n;

    cin >> a >> b;

    //cout << "a = " << a << " rev = " << rev(a) << '\n';

    vector<int>v;

    int pos = sz(a) - 1;
    while(b[pos] == a[pos])pos--;

    while(pos >= 0){

        if(pos == 0){
            v.pb(1);
            a[0] = b[0];
        }else{
            if(b[pos] == a[0])a[0] = (b[pos] == '0' ? '1' : '0'), v.pb(1);
            v.pb(pos + 1);
            string cur = "";
            for(int i = 0; i <= pos; i++)cur += a[i];
            cur = rev(cur);
            for(int i = 0; i < sz(cur); i++)a[i] = cur[i];
        }

        while(b[pos] == a[pos])pos--;
    }

    cout << sz(v) << '\n';
    for(auto it : v)cout << it << ' '; cout << '\n';
}

int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

   // cout << setprecision(6) << fixed;

    int T = 1;
    cin >> T;
    while(T--){
        solve();
    }
}


#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rc(s) return cout<<s,0
#define pi pair <int, int>
#define sz(x) (int)((x).size())
#define int long long

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

const ll inf = 2e9;
const ll mod = 1e9 + 7;
const int N = 1e6 + 11;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);

ifstream in(".in");
ofstream out(".out");

int n, m;// a[N];
string a, b;

void solve(){

    cin >> n;

    cin >> a >> b;

    vector<int>v1,v2;

    a += '0';
    b += '0';

    for(int i = 1; i <= n; i++){
        if(a[i] != a[i - 1])v1.pb(i);
        if(b[i] != b[i - 1])v2.pb(i);
    }

    reverse(all(v2));
    cout << sz(v1) << '\n';
    for(auto it : v1)cout << it << ' ';
    cout << sz(v2) << '\n';
    for(auto it : v2)cout << it << ' ';
    cout << '\n';
}

int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);

   // cout << setprecision(6) << fixed;

    int T = 1;
    cin >> T;
    while(T--){
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;

//#include<ext/pb_ds/assoc_container.hpp> // Common file
//#include<ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order
// order_of_key

mt19937 rand32(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 rand64(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
const int maxn = 100001;

int n; string a, b;

struct node{
    ll val, sum;
    int sz, prior, key;
    bool rev, ch;
    node * l, * r;
    node(){}
    node(ll _val, int _prior, int _key)
    :val(_val),sum(_val),prior(_prior),key(_key),sz(1),l(0),r(0),rev(0),ch(0){}
};

typedef node * pnode;

pnode root;

int size(pnode u){ return u? u->sz: 0; }
ll sum(pnode u){ return u? u->sum: 0; }

void push (pnode it) {
    if (it && it->rev) {
        it->rev = false;
        swap (it->l, it->r);
        if (it->l)  it->l->rev ^= true;
        if (it->r)  it->r->rev ^= true;
    }
    if(it && it->ch){
        it->ch = false;
        if(it->val == '0')
            it->val = '1';
        else
            it->val = '0';
        if(it->l) it->l->ch ^= true;
        if(it->r) it->r->ch ^= true;
    }
}

void upd(pnode u){
    if(!u) return;
    u->sz = size(u->l) + size(u->r) + 1;
    u->sum = sum(u->l) + sum(u->r) + u->val;
}

void merge(pnode &u, pnode L, pnode R){
    push(L);
    push(R);
    if (!L || !R)
        u = L ? L : R;
    else if (L->prior > R->prior)
        merge (L->r, L->r, R),  u = L;
    else
        merge (R->l, L, R->l),  u = R;
    upd(u);
}

void split (pnode u, pnode &L, pnode &R, int key, int add = 0) { /// splits in (-INF, key] and [key+1, INF)
    if (!u) return void( L = R = 0 );
    push(u);
    int cur_key = add + size(u->l) + 1;
    if (key < cur_key)
        split (u->l, L, u->l, key, add),  R = u;
    else
        split (u->r, u->r, R, key, cur_key),  L = u;
    upd(u);
}

void build(pnode &u, int l, int r){
    if(l > r){u = 0; return;}
    int mid = (l+r)>>1;
    u = new node(a[mid],rand32(),mid);
    if(l != r){
        build(u->l,l,mid-1);
        build(u->r,mid+1,r);
    }
    upd(u);
}

void change(int l, int r){
    pnode t1, t2, t3;
    split(root,t1,t2,l-1); /// <= l-1
    split(t2,t2,t3,r-l+1); /// <= r-l+1
    t2->ch ^= true;
//    if(l == r){
//        if(t2->val == '0') t2->val = '1';
//        else t2->val = '0';
//    }
    merge(root, t1, t2);
    merge(root, root, t3);
}

void rever(int l, int r){
    pnode t1, t2, t3;
    split(root,t1,t2,l-1); /// <= l-1
    split(t2,t2,t3,r-l+1); /// <= r-l+1
    t2->rev ^= 1;
    merge(root, t1, t2);
    merge(root, root, t3);
}

int get_value(int pos){
    pnode t1, t2, t3;
    split(root,t2,t3,pos);
    split(t2,t1,t2,pos-1);
    int res = t2->val;
    merge(t1,t1,t2);
    merge(root,t1,t3);
    return res;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);

    int t;
    cin >> t;
    vector<int> ans;
    while(t--){
        cin >> n;
        cin >> a >> b;
        ans.clear();
        a = '$' + a;
        b = '$' + b;
        build(root,1,n);

        for(int i = n; i >= 1; i--){
            a[i] = get_value(i);
            if(a[i] == b[i]) continue;
            if(a[i] != a[1]){
                ans.push_back(1);
                change(1,1);
            }

            change(1,i);
            rever(1,i);

            ans.push_back(i);
        }
        cout << ans.size() << ' ';
        for(int i:ans)
            cout << i << ' ';
        cout << '\n';
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

//#include<ext/pb_ds/assoc_container.hpp> // Common file
//#include<ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order
// order_of_key

//mt19937 rand32(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 rand64(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 100001;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);

    int t, n;
    cin >> t;
    string a, b;
    vector<int> ans;
    while(t--){
        cin >> n;
        cin >> a >> b;
        ans.clear();
        for(int i = n-1; i >= 0; i--){
            if(a[i] == b[i]) continue;
            if(a[i] != a[0]){
                ans.push_back(1);
                if(a[0] == '0') a[0] = '1';
                else a[0] = '0';
            }
            ans.push_back(i+1);
        }
        cout << ans.size() << ' ';
        for(int i:ans)
            cout << i << ' ';
        cout << '\n';
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

//#include<ext/pb_ds/assoc_container.hpp> // Common file
//#include<ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order
// order_of_key

mt19937 rand32(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 rand64(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
const int maxn = 100001;

int n; string a, b;

struct node{
    ll val, sum;
    int sz, prior, key;
    bool rev, ch;
    node * l, * r;
    node(){}
    node(ll _val, int _prior, int _key)
    :val(_val),sum(_val),prior(_prior),key(_key),sz(1),l(0),r(0),rev(0),ch(0){}
};

typedef node * pnode;

pnode root;

int size(pnode u){ return u? u->sz: 0; }
ll sum(pnode u){ return u? u->sum: 0; }

void push (pnode it) {
    if (it && it->rev) {
        it->rev = false;
        swap (it->l, it->r);
        if (it->l)  it->l->rev ^= true;
        if (it->r)  it->r->rev ^= true;
    }
    if(it && it->ch){
        it->ch = false;
        if(it->val == '0') it->val = '1';
        else it->val = '0';
        if(it->l) it->l->ch ^= true;
        if(it->r) it->r->ch ^= true;
    }
}

void upd(pnode u){
    if(!u) return;
    u->sz = size(u->l) + size(u->r) + 1;
    u->sum = sum(u->l) + sum(u->r) + u->val;
}

void merge(pnode &u, pnode L, pnode R){
    push(L);
    push(R);
    if (!L || !R)
        u = L ? L : R;
    else if (L->prior > R->prior)
        merge (L->r, L->r, R),  u = L;
    else
        merge (R->l, L, R->l),  u = R;
    upd(u);
}

void split (pnode u, pnode &L, pnode &R, int key, int add = 0) { /// splits in (-INF, key] and [key+1, INF)
    if (!u) return void( L = R = 0 );
    push(u);
    int cur_key = add + size(u->l) + 1;
    if (key < cur_key)
        split (u->l, L, u->l, key, add),  R = u;
    else
        split (u->r, u->r, R, key, cur_key),  L = u;
    upd(u);
}

void build(pnode &u, int l, int r){
    if(l > r){u = 0; return;}
    int mid = (l+r)>>1;
    u = new node(a[mid],rand32(),mid);
    if(l != r){
        build(u->l,l,mid-1);
        build(u->r,mid+1,r);
    }
    upd(u);
}

void change(int l, int r){
    pnode t1, t2, t3;
    split(root,t1,t2,l-1); /// <= l-1
    split(t2,t2,t3,r-l+1); /// <= r-l+1
    t2->ch ^= true;
    merge(root, t1, t2);
    merge(root, root, t3);
}

void rever(int l, int r){
    pnode t1, t2, t3;
    split(root,t1,t2,l-1); /// <= l-1
    split(t2,t2,t3,r-l+1); /// <= r-l+1
    t2->rev ^= 1;
    merge(root, t1, t2);
    merge(root, root, t3);
}

int get_value(int pos){
    pnode t1, t2, t3;
    split(root,t2,t3,pos);
    split(t2,t1,t2,pos-1);
    if(t2->ch)
        push(t2);
    int res = t2->val;
    merge(t1,t1,t2);
    merge(root,t1,t3);
    return res;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);

    int t;
    cin >> t;
    vector<int> ans;
    while(t--){
        cin >> n;
        cin >> a >> b;
        ans.clear();
        a = '$' + a;
        b = '$' + b;
        build(root,1,n);

        for(int i = n; i >= 1; i--){
            a[i] = get_value(i);
            a[1] = get_value(1);
            if(a[i] == b[i]) continue;
            if(a[i] != a[1]){
                ans.push_back(1);
                change(1,1);
            }

            change(1,i);
            rever(1,i);

            ans.push_back(i);
        }
        cout << ans.size() << ' ';
        for(int i:ans)
            cout << i << ' ';
        cout << '\n';

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

//#include<ext/pb_ds/assoc_container.hpp> // Common file
//#include<ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order
// order_of_key

mt19937 rand32(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 rand64(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
const int maxn = 100001;

int n; string a, b;

struct node{
    ll val, sum;
    int sz, prior, key;
    bool rev, ch;
    node * l, * r;
    node(){}
    node(ll _val, int _prior, int _key)
    :val(_val),sum(_val),prior(_prior),key(_key),sz(1),l(0),r(0),rev(0),ch(0){}
};

typedef node * pnode;

pnode root;

int size(pnode u){ return u? u->sz: 0; }
ll sum(pnode u){ return u? u->sum: 0; }

void push (pnode it) {
    if (it && it->rev) {
        it->rev = false;
        swap (it->l, it->r);
        if (it->l)  it->l->rev ^= true;
        if (it->r)  it->r->rev ^= true;
    }
    if(it && it->ch){
        it->ch = false;
        if(it->l) it->l->ch ^= true;
        if(it->r) it->r->ch ^= true;
    }
}

void upd(pnode u){
    if(!u) return;
    u->sz = size(u->l) + size(u->r) + 1;
    u->sum = sum(u->l) + sum(u->r) + u->val;
}

void merge(pnode &u, pnode L, pnode R){
    push(L);
    push(R);
    if (!L || !R)
        u = L ? L : R;
    else if (L->prior > R->prior)
        merge (L->r, L->r, R),  u = L;
    else
        merge (R->l, L, R->l),  u = R;
    upd(u);
}

void split (pnode u, pnode &L, pnode &R, int key, int add = 0) { /// splits in (-INF, key] and [key+1, INF)
    if (!u) return void( L = R = 0 );
    push(u);
    int cur_key = add + size(u->l) + 1;
    if (key < cur_key)
        split (u->l, L, u->l, key, add),  R = u;
    else
        split (u->r, u->r, R, key, cur_key),  L = u;
    upd(u);
}

void build(pnode &u, int l, int r){
    if(l > r){u = 0; return;}
    int mid = (l+r)>>1;
    u = new node(a[mid],rand32(),mid);
    if(l != r){
        build(u->l,l,mid-1);
        build(u->r,mid+1,r);
    }
    upd(u);
}

void change(int l, int r){
    pnode t1, t2, t3;
    split(root,t1,t2,l-1); /// <= l-1
    split(t2,t2,t3,r-l+1); /// <= r-l+1
    t2->ch ^= true;
    if(l == r){
        if(t2->val == '0') t2->val = '1';
        else t2->val = '0';
    }
    merge(root, t1, t2);
    merge(root, root, t3);
}

void rever(int l, int r){
    pnode t1, t2, t3;
    split(root,t1,t2,l-1); /// <= l-1
    split(t2,t2,t3,r-l+1); /// <= r-l+1
    t2->rev ^= 1;
    merge(root, t1, t2);
    merge(root, root, t3);
}

int get_value(int pos){
    pnode t1, t2, t3;
    split(root,t2,t3,pos);
    split(t2,t1,t2,pos-1);
    int res = t2->val;
    merge(t1,t1,t2);
    merge(root,t1,t3);
    return res;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);

    int t;
    cin >> t;
    vector<int> ans;
    while(t--){
        cin >> n;
        cin >> a >> b;
        ans.clear();
        a = '$' + a;
        b = '$' + b;
        build(root,1,n);

        for(int i = n; i >= 1; i--){
            a[i] = get_value(i);
            if(a[i] == b[i]) continue;
            if(a[i] != a[1]){
                ans.push_back(1);
                change(1,1);
            }

            change(1,i);
            rever(1,i);

            ans.push_back(i);
        }
        cout << ans.size() << ' ';
        for(int i:ans)
            cout << i << ' ';
        cout << '\n';
    }

    return 0;
}


//R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi >
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>

using namespace std;

void solve()
  {
	int n;
	cin>>n;
	string a,b;
	cin>>a>>b;
	vi v;
	int curr=0,x=0;
	repD(i,n-1,0)
	{
		x++;
		if(a[i]==b[i])continue;
		curr++;

		if(b[i]==a[0]){v.pb(1);if(a[0]=='1')a[0]='0';else a[0]='1';}
		// else cout<<1-(b[i]-'0')<<endl;
		if(curr&1)
		{
			int val=a[n-(curr/2+1)];
			val=1-val;
			a[0]=char(val+'0');
		}
		else a[0]=a[curr-1];

		v.pb(i+1);

	}
	cout<<sz(v)<<" ";

	trav(v)cout<<i<<" ";
	cout<<endl;

  }

signed main()
{
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   t=1;
   cin>>t;
   while(t--)
    {
        solve();
    }

   return 0;
}


//R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi >
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>

using namespace std;

void solve()
  {
	int n;
	cin>>n;
	string a,b;
	cin>>a>>b;
	vi v;
	int curr=0,x=0,minm=0,maxm=n-1;
	repD(i,n-1,0)
	{
		x++;
		if(a[i]==b[i])continue;
		curr++;

		if(b[i]==a[0]){v.pb(1);}
		// else cout<<1-(b[i]-'0')<<endl;
		if(curr%2==0)
		{
			int tempv=n-(maxm-minm);
			x-=tempv;

			maxm-=x;
			int val=a[maxm];
			val=1-val;
			a[0]=char(val+'0');
		}
		else
		{
			int tempv=n-(maxm-minm);
			x-=tempv;
			minm-=x;
			a[0]=a[minm];
		}

		v.pb(i+1);

	}
	cout<<sz(v)<<" ";

	trav(v)cout<<i<<" ";
	cout<<endl;

  }

signed main()
{
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   t=1;
   cin>>t;
   while(t--)
    {
        solve();
    }

   return 0;
}


//R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi >
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>

using namespace std;

void solve()
  {
	int n;
	cin>>n;
	string a,b;
	cin>>a>>b;
	vi v;
	int curr=0,x=0,minm=0,maxm=n-1;
	repD(i,n-1,0)
	{
		x++;
		if(a[i]==b[i])continue;
		curr++;

		if(b[i]==a[0]){v.pb(1);if(a[0]=='1')a[0]='0';else a[0]='1';}
		// else cout<<1-(b[i]-'0')<<endl;
		if(curr&1)
		{
			int tempv=n-(maxm-minm);
			x-=tempv;

			maxm-=x;
			int val=a[maxm];
			val=1-val;
			a[0]=char(val+'0');
		}
		else
		{
			int tempv=n-(maxm-minm);
			x-=tempv;
			minm-=x;
			a[0]=a[minm];
		}

		v.pb(i+1);

	}
	cout<<sz(v)<<" ";

	trav(v)cout<<i<<" ";
	cout<<endl;

  }

signed main()
{
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   t=1;
   cin>>t;
   while(t--)
    {
        solve();
    }

   return 0;
}


//R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi >
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>

using namespace std;

void solve()
  {
	int n;
	cin>>n;
	string a,b;
	cin>>a>>b;
	vi v;
	int curr=0,x=0;
	rep(i,n/2)
	{
		if(a[i]!=b[i])v.pb(i+1);

	}
	cout<<sz(v)<<" ";

	trav(v)cout<<i<<" ";
	cout<<endl;

  }

signed main()
{
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   t=1;
   cin>>t;
   while(t--)
    {
        solve();
    }

   return 0;
}


//R<3S
#include <bits/stdc++.h>
#define hell 1000000007
#define PI 3.14159265358979323844
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define endl "\n"
#define vecmax(v) max_element(all(v))
#define vecmin(v) min_element(all(v))
#define GCD(m,n) __gcd(m,n)
#define LCM(m,n) m*(n/GCD(m,n))
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(x) for(auto i : x)
#define sz(a) (int)a.size()
#define sl(a) (int)a.length()
#define int long long
#define ld long double
#define pii std::pair<int, int>
#define pll std::pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi >
#define vii vector<pii >
#define mii map<int,int>
#define mll map<ll,ll>

using namespace std;

void solve()
  {
	int n;
	cin>>n;
	string a,b;
	cin>>a>>b;
	vi v;
	int curr=0,x=0,minm=0,maxm=n-1;
	repD(i,n-1,0)
	{
		x++;
		char cmp=a[i];
		if(curr!=0&&curr%2==1)
		{

			if(a[minm]=='0')cmp='1';
			else cmp='0';
		}
		else if(curr!=0)
		{

			cmp=a[maxm];
		}

		if(cmp==b[i]){if(curr&&curr&1)minm++;else if(curr) maxm--;continue;}

		// cout<<minm<<" "<<maxm<<" ";
		cmp=a[0];
		if(curr!=0&&curr%2==1)
		{

			if(a[maxm]=='0')cmp='1';
			else cmp='0';
		}
		else if(curr!=0)
		{

			cmp=a[minm];
		}
		if(b[i]==cmp)
		{
			// cout<<b[i]<<"."<<endl;
			v.pb(1);

		}
		// else cout<<1-(b[i]-'0')<<endl;

		curr++;

		v.pb(i+1);

		if(curr%2==1)
		{
			int tempv=n-(maxm-minm);
			int tx=x+1-tempv;
			minm+=tx;

			if(a[minm]=='0')a[0]='1';
			else a[0]='0';
		}
		else
		{
			int tempv=n-(maxm-minm);
			int tx=x+1-tempv;
			maxm-=tx;
			a[0]=a[maxm];
		}

	}
	// if(a[0]!=b[0])v.pb(1);
	cout<<sz(v)<<" ";

	trav(v)cout<<i<<" ";
	cout<<endl;

  }

signed main()
{
   std::ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   int t;
   t=1;
   cin>>t;
   while(t--)
    {
        solve();
    }

   return 0;
}