#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

#define ll long long int
#define li long int
using namespace std;

typedef vector<long long int> vi;
typedef pair<ll, ll> pi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define EB emplace_back
#define REP(i, x, y) for(long long int i=x ; i<y ; i++)
#define F first
#define PB push_back
#define S second
#define MP make_pair
#define MT make_tuple
#define INF 9999999
#define MOD 1000000007
ll power(ll x, unsigned ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll ans=0;
    char c1=s[0];
    char x=c1;
    ll j=0;

    while(x==c1&& j<=n-1)
    {
        j++;
        x=s[j];
    }

    char c2=s[n-1];
    if(c2==c1)
    {
       if(j==n)
       {
           ans+=power(2,j,998244353);
       }
       else
       {

        ll t=n-1;
        char y=c2;
        while(y==c2 && t>=0)
        {
            t--;
            y=s[t];

        }
        t++;
        ll right=n-t;
        ll left=j;

        ans+=power(2,left,998244353)+power(2,right,998244353);

       }

    }

    else
    {
        ll t=n-1;
        char y=c2;
        while(y==c2 && t>=0)
        {
            t--;
            y=s[t];

        }
        t++;
        ll right=n-t;
        ll left=j;
       cout<<left<<" "<<right<<" ";
        ans+= (left+1)%998244353+right%998244353;

    }
    cout<<ans<<'\n';

    return 0;
}


// by VIDIT BHARDWAJ
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;

// when we want to insert same element multiple times into pbds
// typedef tree<pair<int,int>,null_type,less<pair<int,int > >,rb_tree_tag,tree_order_statistics_node_update> pbds;

#define int                     long long int
#define pb                      push_back
#define mk(arr,n,type)          type *arr=new type[n]; //mk(pos,n,vector<int>)
#define setbits(x)              __builtin_popcountll(x)
#define zerobits(x)             __builtin_ctzll(x)
#define ps(x,y)                 fixed<<setprecision(y)<<x // cout<<ps(1.255114,4)
#define tc(t)                   int t; cin>>t; while(t--)

const long long mod=998244353;
const int inf=1000000000000000000;
const long double pi = 3.14159265358979323846264338;

bool double_compare(double a, double b, double epsilon = 0.001)
{
    return std::abs(a - b) < epsilon;
}
int lcm(int a,int b){
    return (a*b)/__gcd(a,b);
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6){
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    }

    return true;
}
// Fermat's little theorem
int pow(int a, unsigned int b,int mod1){

    int ans=1;
    while(b){

        if(b&1ll){

            ans*=a;
            ans%=mod1;
        }
        b/=2;
        a*=a;
        a%=mod1;
    }

    return ans;
}
int inverse(int a,int mod1){

    return pow(a,mod1-2,mod1);    // a^-1%p
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

signed main()
{
    int n; cin>>n;
    string str; cin>>str;

    int l=0,r=n-1;
    while(str[l]==str[l+1] && l<n-1){
        l++;
    }
    while(str[r]==str[r-1] && r>0){
        r--;
    }

    int left_count=l+1,right_count=n-r;
    cout<<left_count<<" "<<right_count<<endl;

    if(str[0]==str[n-1]){
        cout<<((left_count+1)*(right_count+1)%mod;
    }
    else{
        cout<<(left_count+right_count+1+mod)%mod;
    }

    return 0;
}

/*

*/


// by VIDIT BHARDWAJ
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;

// when we want to insert same element multiple times into pbds
// typedef tree<pair<int,int>,null_type,less<pair<int,int > >,rb_tree_tag,tree_order_statistics_node_update> pbds;

#define int                     long long int
#define pb                      push_back
#define mk(arr,n,type)          type *arr=new type[n]; //mk(pos,n,vector<int>)
#define setbits(x)              __builtin_popcountll(x)
#define zerobits(x)             __builtin_ctzll(x)
#define ps(x,y)                 fixed<<setprecision(y)<<x // cout<<ps(1.255114,4)
#define tc(t)                   int t; cin>>t; while(t--)

const long long mod=998244353;
const int inf=1000000000000000000;
const long double pi = 3.14159265358979323846264338;

bool double_compare(double a, double b, double epsilon = 0.001)
{
    return std::abs(a - b) < epsilon;
}
int lcm(int a,int b){
    return (a*b)/__gcd(a,b);
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6){
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    }

    return true;
}
// Fermat's little theorem
int pow(int a, unsigned int b,int mod1){

    int ans=1;
    while(b){

        if(b&1ll){

            ans*=a;
            ans%=mod1;
        }
        b/=2;
        a*=a;
        a%=mod1;
    }

    return ans;
}
int inverse(int a,int mod1){

    return pow(a,mod1-2,mod1);    // a^-1%p
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

signed main()
{
    int n; cin>>n;
    string str; cin>>str;

    int l=0,r=n-1;
    while(str[l]==str[l+1] && l<n-1){
        l++;
    }
    while(str[r]==str[r-1] && r>0){
        r--;
    }

    int left_count=l+1,right_count=n-r;

    if(str[0]==str[n-1]){
        cout<<((left_count+1)*right_count)%mod;
    }
    else{
        cout<<(left_count+right_count+1)%mod;
    }

    return 0;
}

/*

*/


// by VIDIT BHARDWAJ
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;

// when we want to insert same element multiple times into pbds
// typedef tree<pair<int,int>,null_type,less<pair<int,int > >,rb_tree_tag,tree_order_statistics_node_update> pbds;

#define int                     long long int
#define pb                      push_back
#define mk(arr,n,type)          type *arr=new type[n]; //mk(pos,n,vector<int>)
#define setbits(x)              __builtin_popcountll(x)
#define zerobits(x)             __builtin_ctzll(x)
#define ps(x,y)                 fixed<<setprecision(y)<<x // cout<<ps(1.255114,4)
#define tc(t)                   int t; cin>>t; while(t--)

const long long mod=998244353;
const int inf=1000000000000000000;
const long double pi = 3.14159265358979323846264338;

bool double_compare(double a, double b, double epsilon = 0.001)
{
    return std::abs(a - b) < epsilon;
}
int lcm(int a,int b){
    return (a*b)/__gcd(a,b);
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6){
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    }

    return true;
}
// Fermat's little theorem
int pow(int a, unsigned int b,int mod1){

    int ans=1;
    while(b){

        if(b&1ll){

            ans*=a;
            ans%=mod1;
        }
        b/=2;
        a*=a;
        a%=mod1;
    }

    return ans;
}
int inverse(int a,int mod1){

    return pow(a,mod1-2,mod1);    // a^-1%p
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

signed main()
{
    int n; cin>>n;
    string str; cin>>str;

    int l=0,r=n-1;
    while(str[l]==str[l+1] && l<n-1){
        l++;
    }
    while(str[r]==str[r-1] && r>0){
        r--;
    }

    int left_count=l+1,right_count=n-r,ans=0;

    for(int i=0;i<l+1;i++){
        if(i==0){
            ans+=(right_count+1+mod)%mod;
        }
        else{
            if(str[i]==str[n-1]){
                ans+=(right_count+1+mod)%mod;
            }
            else{
                ans++;
            }
        }
    }

    if(str[0]==str[n-1]){
        ans+=(right_count+1+mod)%mod;
    }
    else{
        ans++;
    }

    cout<<ans;

    return 0;
}

/*

*/


// by VIDIT BHARDWAJ
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;

// when we want to insert same element multiple times into pbds
// typedef tree<pair<int,int>,null_type,less<pair<int,int > >,rb_tree_tag,tree_order_statistics_node_update> pbds;

#define int                     long long int
#define pb                      push_back
#define mk(arr,n,type)          type *arr=new type[n]; //mk(pos,n,vector<int>)
#define setbits(x)              __builtin_popcountll(x)
#define zerobits(x)             __builtin_ctzll(x)
#define ps(x,y)                 fixed<<setprecision(y)<<x // cout<<ps(1.255114,4)
#define tc(t)                   int t; cin>>t; while(t--)

const long long mod=998244353;
const int inf=1000000000000000000;
const long double pi = 3.14159265358979323846264338;

bool double_compare(double a, double b, double epsilon = 0.001)
{
    return std::abs(a - b) < epsilon;
}
int lcm(int a,int b){
    return (a*b)/__gcd(a,b);
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6){
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    }

    return true;
}
// Fermat's little theorem
int pow(int a, unsigned int b,int mod1){

    int ans=1;
    while(b){

        if(b&1ll){

            ans*=a;
            ans%=mod1;
        }
        b/=2;
        a*=a;
        a%=mod1;
    }

    return ans;
}
int inverse(int a,int mod1){

    return pow(a,mod1-2,mod1);    // a^-1%p
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

signed main()
{
    int n; cin>>n;
    string str; cin>>str;

    int l=0,r=n-1;
    while(str[l]==str[l+1] && l<n-1){
        l++;
    }
    while(str[r]==str[r-1] && r>0){
        r--;
    }

    int left_count=l+1,right_count=n-r;

    if(str[0]==str[n-1]){
        cout<<((left_count)*right_count)%mod;
    }
    else{
        cout<<(left_count+right_count+1+mod)%mod;
    }

    return 0;
}

/*

*/


// by VIDIT BHARDWAJ
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;

// when we want to insert same element multiple times into pbds
// typedef tree<pair<int,int>,null_type,less<pair<int,int > >,rb_tree_tag,tree_order_statistics_node_update> pbds;

#define int                     long long int
#define pb                      push_back
#define mk(arr,n,type)          type *arr=new type[n]; //mk(pos,n,vector<int>)
#define setbits(x)              __builtin_popcountll(x)
#define zerobits(x)             __builtin_ctzll(x)
#define ps(x,y)                 fixed<<setprecision(y)<<x // cout<<ps(1.255114,4)
#define tc(t)                   int t; cin>>t; while(t--)

const long long mod=998244353;
const int inf=1000000000000000000;
const long double pi = 3.14159265358979323846264338;

bool double_compare(double a, double b, double epsilon = 0.001)
{
    return std::abs(a - b) < epsilon;
}
int lcm(int a,int b){
    return (a*b)/__gcd(a,b);
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6){
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    }

    return true;
}
// Fermat's little theorem
int pow(int a, unsigned int b,int mod1){

    int ans=1;
    while(b){

        if(b&1ll){

            ans*=a;
            ans%=mod1;
        }
        b/=2;
        a*=a;
        a%=mod1;
    }

    return ans;
}
int inverse(int a,int mod1){

    return pow(a,mod1-2,mod1);    // a^-1%p
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

signed main()
{
    int n; cin>>n;
    string str; cin>>str;

    int l=0,r=n-1;
    while(str[l]==str[l+1] && l<n-1){
        l++;
    }
    while(str[r]==str[r-1] && r>0){
        r--;
    }

    int left_count=l+1,right_count=n-r,ans=0;

    for(int i=0;i<l+1;i++){
        if(i==0){
            ans+=(right_count+1)%mod;
        }
        else{
            if(str[i]==str[n-1]){
                ans+=(right_count+1)%mod;
            }
            else{
                ans++;
            }
        }
    }

    if(str[0]==str[n-1]){
        ans+=(right_count+1)%mod;
    }
    else{
        ans++;
    }

    cout<<ans;

    return 0;
}

/*

*/


// by VIDIT BHARDWAJ
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;

// when we want to insert same element multiple times into pbds
// typedef tree<pair<int,int>,null_type,less<pair<int,int > >,rb_tree_tag,tree_order_statistics_node_update> pbds;

#define int                     long long int
#define pb                      push_back
#define mk(arr,n,type)          type *arr=new type[n]; //mk(pos,n,vector<int>)
#define setbits(x)              __builtin_popcountll(x)
#define zerobits(x)             __builtin_ctzll(x)
#define ps(x,y)                 fixed<<setprecision(y)<<x // cout<<ps(1.255114,4)
#define tc(t)                   int t; cin>>t; while(t--)

const long long mod=998244353;
const int inf=1000000000000000000;
const long double pi = 3.14159265358979323846264338;

bool double_compare(double a, double b, double epsilon = 0.001)
{
    return std::abs(a - b) < epsilon;
}
int lcm(int a,int b){
    return (a*b)/__gcd(a,b);
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6){
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    }

    return true;
}
// Fermat's little theorem
int pow(int a, unsigned int b,int mod1){

    int ans=1;
    while(b){

        if(b&1ll){

            ans*=a;
            ans%=mod1;
        }
        b/=2;
        a*=a;
        a%=mod1;
    }

    return ans;
}
int inverse(int a,int mod1){

    return pow(a,mod1-2,mod1);    // a^-1%p
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

signed main()
{
    int n; cin>>n;
    string str; cin>>str;

    int l=0,r=n-1;
    while(str[l]==str[l+1] && l<n-1){
        l++;
    }
    while(str[r]==str[r-1] && r>0){
        r--;
    }

    int left_count=l+1,right_count=n-r;

    if(str[0]==str[n-1]){
        cout<<((left_count+1)*(right_count+1))%mod;
    }
    else{
        cout<<(left_count+right_count+1+mod)%mod;
    }

    return 0;
}

/*

*/


// by VIDIT BHARDWAJ
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;

// when we want to insert same element multiple times into pbds
// typedef tree<pair<int,int>,null_type,less<pair<int,int > >,rb_tree_tag,tree_order_statistics_node_update> pbds;

#define int                     long long int
#define pb                      push_back
#define mk(arr,n,type)          type *arr=new type[n]; //mk(pos,n,vector<int>)
#define setbits(x)              __builtin_popcountll(x)
#define zerobits(x)             __builtin_ctzll(x)
#define ps(x,y)                 fixed<<setprecision(y)<<x // cout<<ps(1.255114,4)
#define tc(t)                   int t; cin>>t; while(t--)

const long long mod=998244353;
const int inf=1000000000000000000;
const long double pi = 3.14159265358979323846264338;

bool double_compare(double a, double b, double epsilon = 0.001)
{
    return std::abs(a - b) < epsilon;
}
int lcm(int a,int b){
    return (a*b)/__gcd(a,b);
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6){
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    }

    return true;
}
// Fermat's little theorem
int pow(int a, unsigned int b,int mod1){

    int ans=1;
    while(b){

        if(b&1ll){

            ans*=a;
            ans%=mod1;
        }
        b/=2;
        a*=a;
        a%=mod1;
    }

    return ans;
}
int inverse(int a,int mod1){

    return pow(a,mod1-2,mod1);    // a^-1%p
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

signed main()
{
    int n; cin>>n;
    string str; cin>>str;

    int l=0,r=n-1;
    while(str[l]==str[l+1] && l<n-1){
        l++;
    }
    while(str[r]==str[r-1] && r>0){
        r--;
    }

    int left_count=l+1,right_count=n-r;
    cout<<left_count<<" "<<right_count<<endl;

    if(str[0]==str[n-1]){
        cout<<((left_count+1)*(right_count+1))%mod;
    }
    else{
        cout<<(left_count+right_count+1+mod)%mod;
    }

    return 0;
}

/*

*/


//Here I come unstoppable_N
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define booster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PB push_back
#define F first
#define S second
#define forn(i,n) for(int i=0;i<n;i++)
#define vi vector<int>

const int mod=1e9+7;
ll xor1_n(ll n){switch(n%4){case 0:return n;case 1:return 1;case 2:return n+1;}return 0;}
int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }
clock_t time_p=clock();
void rtime(){ time_p=clock()-time_p; cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll gcd(ll a,ll b){	if(b==0) return a;	return gcd(b,a%b);}
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll comp(ll a,ll b){ return (a<b); }

int rr[]={0,1,1,1,0,-1,-1,-1,};
int cc[]={1,1,0,-1,-1,-1,0,1};

int tau(int n)
{
	int p=1;
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			int c=0;
			while(n%i==0)
			{
				c++;
				n/=i;
			}
			p*=c+1;
		}
	}
	if(n>1)
		p*=2;
	return p;
}

int main()
{
	//freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		int l=0,r=0;
		for(int i=0;i<n;i++)
		{
			if(s[i]==s[0])
				l++;
			else break;
		}
		for(int i=n-1;i>=0;i--)
		{
			if(s[i]==s[n-1])
				r++;
			else break;
		}
		if(s[0]==s[n-1])
		{
			cout<<((l+1)*1ll*(r+1))%998244353;
		}
		else cout<<(l+r-1)%998244353;
	}
	rtime();
	return 0;
}


//Here I come unstoppable_N
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define booster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PB push_back
#define F first
#define S second
#define forn(i,n) for(int i=0;i<n;i++)
#define vi vector<int>

const int mod=1e9+7;
ll xor1_n(ll n){switch(n%4){case 0:return n;case 1:return 1;case 2:return n+1;}return 0;}
int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }
clock_t time_p=clock();
void rtime(){ time_p=clock()-time_p; cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll gcd(ll a,ll b){	if(b==0) return a;	return gcd(b,a%b);}
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll comp(ll a,ll b){ return (a<b); }

int rr[]={0,1,1,1,0,-1,-1,-1,};
int cc[]={1,1,0,-1,-1,-1,0,1};

int tau(int n)
{
	int p=1;
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			int c=0;
			while(n%i==0)
			{
				c++;
				n/=i;
			}
			p*=c+1;
		}
	}
	if(n>1)
		p*=2;
	return p;
}

int main()
{
	//freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		int l=n,r=n;
		for(int i=0;i<n;i++)
		{
			if(i)
			{
				if(s[i]!=s[i-1])
				{
					l=i;
					break;
				}
			}
		}
		reverse(s.begin(),s.end());
		for(int i=0;i<n;i++)
		{
			if(i)
			{
				if(s[i]!=s[i-1])
				{
					r=i;
					break;
				}
			}
		}
		if(l==r && l==n)
		{
			l=0;
		}
		int m=998244353;
		if(s[0]==s[n-1])
		{
			ll x=((l+1)%m)*((r+1)%m);
			cout<<(x)%m;
		}
		else cout<<(l+r+1)%m;
	}
	rtime();
	return 0;
}


//Here I come unstoppable_N
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define booster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PB push_back
#define F first
#define S second
#define forn(i,n) for(int i=0;i<n;i++)
#define vi vector<int>

const int mod=1e9+7;
ll xor1_n(ll n){switch(n%4){case 0:return n;case 1:return 1;case 2:return n+1;}return 0;}
int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }
clock_t time_p=clock();
void rtime(){ time_p=clock()-time_p; cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll gcd(ll a,ll b){	if(b==0) return a;	return gcd(b,a%b);}
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll comp(ll a,ll b){ return (a<b); }

int rr[]={0,1,1,1,0,-1,-1,-1,};
int cc[]={1,1,0,-1,-1,-1,0,1};

int tau(int n)
{
	int p=1;
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			int c=0;
			while(n%i==0)
			{
				c++;
				n/=i;
			}
			p*=c+1;
		}
	}
	if(n>1)
		p*=2;
	return p;
}

int main()
{
	//freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		int l=0,r=0;
		for(int i=0;i<n;i++)
		{
			if(i)
			{
				if(s[i]!=s[i-1])
				{
					l=i;
					break;
				}
			}
		}
		reverse(s.begin(),s.end());
		for(int i=0;i<n;i++)
		{
			if(i)
			{
				if(s[i]!=s[i-1])
				{
					r=i;
					break;
				}
			}
		}
		int m=998244353;
		if(s[0]==s[n-1])
		{
			cout<<((l+1)%m*(r+1)%m)%m;
		}
		else cout<<l+r+1;
	}
	rtime();
	return 0;
}


//Here I come unstoppable_N
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define booster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PB push_back
#define F first
#define S second
#define forn(i,n) for(int i=0;i<n;i++)
#define vi vector<int>

const int mod=1e9+7;
ll xor1_n(ll n){switch(n%4){case 0:return n;case 1:return 1;case 2:return n+1;}return 0;}
int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }
clock_t time_p=clock();
void rtime(){ time_p=clock()-time_p; cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll gcd(ll a,ll b){	if(b==0) return a;	return gcd(b,a%b);}
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll comp(ll a,ll b){ return (a<b); }

int rr[]={0,1,1,1,0,-1,-1,-1,};
int cc[]={1,1,0,-1,-1,-1,0,1};

int tau(int n)
{
	int p=1;
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			int c=0;
			while(n%i==0)
			{
				c++;
				n/=i;
			}
			p*=c+1;
		}
	}
	if(n>1)
		p*=2;
	return p;
}

int main()
{
	//freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		int l=n,r=n;
		for(int i=0;i<n;i++)
		{
			if(i)
			{
				if(s[i]!=s[i-1])
				{
					l=i;
					break;
				}
			}
		}
		reverse(s.begin(),s.end());
		for(int i=0;i<n;i++)
		{
			if(i)
			{
				if(s[i]!=s[i-1])
				{
					r=i;
					break;
				}
			}
		}
		if(l==r && l==n)
		{
			l=0;
		}
		int m=998244353;
		if(s[0]==s[n-1])
		{
			cout<<((l+1)%m*(r+1)%m)%m;
		}
		else cout<<(l+r+1)%m;
	}
	rtime();
	return 0;
}


//Here I come unstoppable_N
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define booster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PB push_back
#define F first
#define S second
#define forn(i,n) for(int i=0;i<n;i++)
#define vi vector<int>

const int mod=1e9+7;
ll xor1_n(ll n){switch(n%4){case 0:return n;case 1:return 1;case 2:return n+1;}return 0;}
int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }
clock_t time_p=clock();
void rtime(){ time_p=clock()-time_p; cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll gcd(ll a,ll b){	if(b==0) return a;	return gcd(b,a%b);}
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll comp(ll a,ll b){ return (a<b); }

int rr[]={0,1,1,1,0,-1,-1,-1,};
int cc[]={1,1,0,-1,-1,-1,0,1};

int tau(int n)
{
	int p=1;
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			int c=0;
			while(n%i==0)
			{
				c++;
				n/=i;
			}
			p*=c+1;
		}
	}
	if(n>1)
		p*=2;
	return p;
}

int main()
{
	//freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		int l=0,r=0;
		for(int i=0;i<n;i++)
		{
			if(s[i]==s[0])
				l++;
			else break;
		}
		for(int i=n-1;i>=0;i--)
		{
			if(s[i]==s[n-1])
				r++;
			else break;
		}
		if(s[0]==s[n-1])
		{
			cout<<((l+1)*1ll*(r+1))%998244353;
		}
		else cout<<(l+r+1)%998244353;
	}
	rtime();
	return 0;
}


//Here I come unstoppable_N
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define booster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PB push_back
#define F first
#define S second
#define forn(i,n) for(int i=0;i<n;i++)
#define vi vector<int>

const int mod=1e9+7;
ll xor1_n(ll n){switch(n%4){case 0:return n;case 1:return 1;case 2:return n+1;}return 0;}
int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }
clock_t time_p=clock();
void rtime(){ time_p=clock()-time_p; cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll gcd(ll a,ll b){	if(b==0) return a;	return gcd(b,a%b);}
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll comp(ll a,ll b){ return (a<b); }

int rr[]={0,1,1,1,0,-1,-1,-1,};
int cc[]={1,1,0,-1,-1,-1,0,1};

int tau(int n)
{
	int p=1;
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			int c=0;
			while(n%i==0)
			{
				c++;
				n/=i;
			}
			p*=c+1;
		}
	}
	if(n>1)
		p*=2;
	return p;
}

int main()
{
	//freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		int l=n,r=n;
		for(int i=0;i<n;i++)
		{
			if(i)
			{
				if(s[i]!=s[i-1])
				{
					l=i;
					break;
				}
			}
		}
		reverse(s.begin(),s.end());
		for(int i=0;i<n;i++)
		{
			if(i)
			{
				if(s[i]!=s[i-1])
				{
					r=i;
					break;
				}
			}
		}
		ll ans=0;
		int m=998244353;
		if(l==r && l==n)
		{
			ans=1ll*n*(n+1)/2;
		}
		else
		{
			if(s[0]==s[n-1])
			{
				ans=((l+1)%m)*((r+1)%m);
			}
			else ans=(l+r+1)%m;
		}
		cout<<ans%m;
	}
	rtime();
	return 0;
}


//Here I come unstoppable_N
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define booster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PB push_back
#define F first
#define S second
#define forn(i,n) for(int i=0;i<n;i++)
#define vi vector<int>

const int mod=1e9+7;
ll xor1_n(ll n){switch(n%4){case 0:return n;case 1:return 1;case 2:return n+1;}return 0;}
int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res; }
clock_t time_p=clock();
void rtime(){ time_p=clock()-time_p; cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll gcd(ll a,ll b){	if(b==0) return a;	return gcd(b,a%b);}
ll power(ll a,ll b,ll m=mod){ ll ans=1; a=a%m;  while(b>0) {  if(b&1)  ans=(1ll*a*ans)%m; b>>=1;a=(1ll*a*a)%m;}return ans;}
ll comp(ll a,ll b){ return (a<b); }

int rr[]={0,1,1,1,0,-1,-1,-1,};
int cc[]={1,1,0,-1,-1,-1,0,1};

int tau(int n)
{
	int p=1;
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			int c=0;
			while(n%i==0)
			{
				c++;
				n/=i;
			}
			p*=c+1;
		}
	}
	if(n>1)
		p*=2;
	return p;
}

int main()
{
	//freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
		int n;
		string s;
		cin>>n>>s;
		int l=0,r=0;
		for(int i=0;i<n;i++)
		{
			if(i)
			{
				if(s[i]!=s[i-1])
				{
					l=i;
					break;
				}
			}
		}
		reverse(s.begin(),s.end());
		for(int i=0;i<n;i++)
		{
			if(i)
			{
				if(s[i]!=s[i-1])
				{
					r=i;
					break;
				}
			}
		}
		if(s[0]==s[n-1])
		{
			cout<<(l+1)*(r+1);
		}
		else cout<<l+r+1;
	}
	rtime();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;cin>>n;
    string s;
    cin>>s;

        ll cf=1;
        ll i;
        for(i=1;i<n;i++)
        {
            if(s[i]==s[0])cf++;
            else {break;}
        }
        ll cb=1;
        ll j;
        for(j=n-2;j>=i;j--)
        {
            if(s[j]==s[n-1])cb++;
            else break;
        }

    if(s[0]==s[n-1])
    {
        cout<<(cf+cb+cf*cb+1ll)%mod;
    }
    else
    {
        cout<<(cf+1ll+cb)%mod;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;cin>>n;
    string s;
    cin>>s;

        ll cf=1;
        ll i;
        for(i=1;i<n;i++)
        {
            if(s[i]==s[0])cf++;
            else {break;}
        }
        ll cb=1;
        ll j;
        for(j=n-2;j>=i;j--)
        {
            if(s[j]==s[n-1])cb++;
            else break;
        }

    if(s[0]==s[n-1])
    {
        ll ans=1;
        ans=(ans+cb)%mod;
        ans=(ans+cf)%mod;
        ans=(ans+cf*cb)%mod;

        cout<<ans;
    }
    else
    {
        ll ans=1;
        ans=(ans+cf)%mod;
        ans=(ans+cb)%mod;
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 998244353

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;cin>>n;
    string s;
    cin>>s;

        ll cf=1;
        ll i;
        for(i=1;i<n;i++)
        {
            if(s[i]==s[0])cf++;
            else {break;}
        }

        ll cb=1;
        ll j;
        for(j=n-2;j>=i;j--)
        {
            if(s[j]==s[n-1])cb++;
            else break;
        }

    if(s[0]==s[n-1] && n!=1)
    {
        cout<<((cf+1ll)*(cb+1ll))%mod;
    }
    else
    {
        cout<<((cf+1ll+cb)%mod;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;cin>>n;
    string s;
    cin>>s;

        ll cf=1;
        ll i;
        for(i=1;i<n;i++)
        {
            if(s[i]==s[0])cf++;
            else {break;}
        }
        ll cb=1;
        ll j;
        for(j=n-2;j>=i;j--)
        {
            if(s[j]==s[n-1])cb++;
            else break;
        }

    if(s[0]==s[n-1])
    {
        cout<<(cf+cb+cf*cb+1)%mod;
    }
    else
    {
        cout<<(cf+1+cb)%mod;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 998244353ll

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;cin>>n;
    string s;
    cin>>s;

        ll cf=1;
        ll i;
        for(i=1;i<n;i++)
        {
            if(s[i]==s[0])cf++;
            else {break;}
        }
        ll cb=1;
        ll j;
        for(j=n-2;j>=0;j--)
        {
            if(s[j]==s[n-1])cb++;
            else break;
        }

    if(s[0]==s[n-1])
    {
        ll ans=1;
        ans=(ans+cb)%mod;
        ans=(ans+cf)%mod;
        ans=(ans+cf*cb)%mod;

        cout<<ans;
    }
    else
    {
        ll ans=1;
        ans=(ans+cf)%mod;
        ans=(ans+cb)%mod;
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;cin>>n;
    string s;
    cin>>s;

        ll cf=1;
        ll i;
        for(i=1;i<n;i++)
        {
            if(s[i]==s[0])cf++;
            else {break;}
        }
        if(i==n)
        {
            cout<<((n*(n+1))/2ll)%mod;
            return 0;
        }
        ll cb=1;
        ll j;
        for(j=n-2;j>=i;j--)
        {
            if(s[j]==s[n-1])cb++;
            else break;
        }

    if(s[0]==s[n-1] && n!=1)
    {
        cout<<((cf+1)*(cb+1))%mod;
    }
    else
    {
        cout<<((cf+1)+(cb+1)-1)%mod;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 998244353ll

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;cin>>n;
    string s;
    cin>>s;

        ll cf=1;
        ll i;
        for(i=1;i<n;i++)
        {
            if(s[i]==s[0])cf++;
            else {break;}
        }
        ll cb=1;
        ll j;
        for(j=n-2;j>=i;j--)
        {
            if(s[j]==s[n-1])cb++;
            else break;
        }

    if(s[0]==s[n-1])
    {
        ll ans=1;
        ans=(ans+cb)%mod;
        ans=(ans+cf)%mod;
        ans=(ans+cf*cb)%mod;

        cout<<ans;
    }
    else
    {
        ll ans=1;
        ans=(ans+cf)%mod;
        ans=(ans+cb)%mod;
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;cin>>n;
    string s;
    cin>>s;

        ll cf=1;
        ll i;
        for(i=1;i<n;i++)
        {
            if(s[i]==s[0])cf++;
            else {break;}
        }
        ll cb=1;
        ll j;
        for(j=n-2;j>=i;j--)
        {
            if(s[j]==s[n-1])cb++;
            else break;
        }

    if(s[0]==s[n-1] && n!=1)
    {
        cout<<((cf+1)*(cb+1))%mod;
    }
    else
    {
        cout<<(cf+1+cb)%mod;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 998244353

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;cin>>n;
    string s;
    cin>>s;

        ll cf=1;
        ll i;
        for(i=1;i<n;i++)
        {
            if(s[i]==s[0])cf++;
            else {break;}
        }

        ll cb=1;
        ll j;
        for(j=n-2;j>=i;j--)
        {
            if(s[j]==s[n-1])cb++;
            else break;
        }

    if(s[0]==s[n-1] && n!=1)
    {
        cout<<((cf+1ll)*(cb+1ll))%mod;
    }
    else
    {
        cout<<(cf+1ll+cb)%mod;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    ll n;cin>>n;
    string s;
    cin>>s;

        ll cf=1;
        ll i;
        for(i=1;i<n;i++)
        {
            if(s[i]==s[0])cf++;
            else {break;}
        }
        ll cb=1;
        ll j;
        for(j=n-2;j>=i;j--)
        {
            if(s[j]==s[n-1])cb++;
            else break;
        }

    if(s[0]==s[n-1])
    {
        cout<<(cf+cb+cf*cb)%mod;
    }
    else
    {
        cout<<(cf+1+cb)%mod;
    }
}


#include <bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include <sstream>

using namespace std;
typedef long long int ll;
#define nl prllf("\n");
#define pp pair<ll,ll>
#define INT_BITS 32
#define ifo(i) (i%2!=0) ? 0 : 1
#define f(i,n) for(int i=0;i<n;i++)
#define fn(i,k,n) for(int i=k;i<n;i++)

// void solve()
// {

// 	int n;
// 	cin >> n;
// 	string m;
// 	cin >> m;
// 	vector<pair<ll,ll> > a(n);
// 	ll x,y;
// 	for(int i=0;i<n;i++)
// 		{	cin >> x;
// 			a[i] = make_pair(x,i+1);
// 		}

// 	sort(a,a+n);
// 	int length = m.length();
// 	for(int i=0;i<length;i++)
// 	{

// 	}

// }

void solve(){

	int n;
	cin >>n ;
	string m;
	cin >> m;
	ll sum=0,sum1=0,sum2=0;
	char a=m[0],b=m[1];

	for(int i=0;i<n;i++)
	{
		if(m[i]==m[i+1])
			{
				a = m[i];sum++;}
		else
			{
				sum++;break;
	}	}

	sum1 = sum;
	sum = 0;

	for(int i=n-1;i>=0;i--)
	{
		if(m[i]==m[i-1])
			{b = m[i];sum++;}
		else
			{
				sum++;break;
	}	}

	sum2 = sum;

	if(a!=b)
	{
		cout << sum1+sum2+1 <<endl;
	}

	else
	{
		cout << 1+ sum1 + sum2 + 2*sum1*sum2 <<endl;
	}

}

int main() {
	// #ifndef opp
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	// cin >> t;

	for(ll i=0;i<t;i++)
	{
		solve();

	}
	return 0;
}


#include <bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include <sstream>

using namespace std;
typedef long long int ll;
#define nl prllf("\n");
#define pp pair<ll,ll>
#define INT_BITS 32
#define ifo(i) (i%2!=0) ? 0 : 1
#define f(i,n) for(int i=0;i<n;i++)
#define fn(i,k,n) for(int i=k;i<n;i++)

// void solve()
// {

// 	int n;
// 	cin >> n;
// 	string m;
// 	cin >> m;
// 	vector<pair<ll,ll> > a(n);
// 	ll x,y;
// 	for(int i=0;i<n;i++)
// 		{	cin >> x;
// 			a[i] = make_pair(x,i+1);
// 		}

// 	sort(a,a+n);
// 	int length = m.length();
// 	for(int i=0;i<length;i++)
// 	{

// 	}

// }

void solve(){

	int n;
	cin >>n ;
	string m;
	cin >> m;
	ll sum=0,sum1=0,sum2=0;
	char a=m[0],b=m[1];

	for(int i=0;i<n;i++)
	{
		if(m[i]==m[i+1])
			{
				a = m[i];
				sum++;
				sum%=998244353 ;}
		else
			{
				sum++;break;
	}	}

	sum1 = sum;
	sum = 0;

	for(int i=n-1;i>=0;i--)
	{
		if(m[i]==m[i-1])
			{b = m[i];sum++;}
		else
			{
				sum++;
				sum%=998244353;break;
	}	}

	sum2 = sum;

	if(a!=b)
	{
		cout << sum1+sum2+1 <<endl;
	}

	else
	{
		cout << 1+ sum1 + sum2 + sum1*sum2 <<endl;
	}

}

int main() {
	// #ifndef opp
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	// cin >> t;

	for(ll i=0;i<t;i++)
	{
		solve();

	}
	return 0;
}


#include <bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include <sstream>

using namespace std;
typedef long long int ll;
#define nl prllf("\n");
#define pp pair<ll,ll>
#define INT_BITS 32
#define ifo(i) (i%2!=0) ? 0 : 1
#define f(i,n) for(int i=0;i<n;i++)
#define fn(i,k,n) for(int i=k;i<n;i++)

// void solve()
// {

// 	int n;
// 	cin >> n;
// 	string m;
// 	cin >> m;
// 	vector<pair<ll,ll> > a(n);
// 	ll x,y;
// 	for(int i=0;i<n;i++)
// 		{	cin >> x;
// 			a[i] = make_pair(x,i+1);
// 		}

// 	sort(a,a+n);
// 	int length = m.length();
// 	for(int i=0;i<length;i++)
// 	{

// 	}

// }

void solve(){

	int n;
	cin >>n ;
	string m;
	cin >> m;
	ll sum=0,sum1=0,sum2=0;
	char a=m[0],b=m[1];
	int length = m.length();
	for(int i=0;i<length;i++)
	{
		if(m[i]==m[i+1])
			{
				a = m[i];sum++;}
		else
			{
				sum++;break;
	}	}

	sum1 = sum;

	for(int i=length-1;i>=0;i--)
	{
		if(m[i]==m[i-1])
			{b = m[i];sum++;}
		else
			{
				sum++;break;
	}	}

	sum2 = sum-sum1;

	if(a!=b)
	{
		cout << sum+1 <<endl;
	}

	else
	{
		cout << sum + sum1 + sum2 <<endl;
	}

}

int main() {
	// #ifndef opp
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	// cin >> t;

	for(ll i=0;i<t;i++)
	{
		solve();

	}
	return 0;
}


#include <bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include <sstream>

using namespace std;
typedef long long int ll;
#define nl prllf("\n");
#define pp pair<ll,ll>
#define INT_BITS 32
#define ifo(i) (i%2!=0) ? 0 : 1
#define f(i,n) for(int i=0;i<n;i++)
#define fn(i,k,n) for(int i=k;i<n;i++)

// void solve()
// {

// 	int n;
// 	cin >> n;
// 	string m;
// 	cin >> m;
// 	vector<pair<ll,ll> > a(n);
// 	ll x,y;
// 	for(int i=0;i<n;i++)
// 		{	cin >> x;
// 			a[i] = make_pair(x,i+1);
// 		}

// 	sort(a,a+n);
// 	int length = m.length();
// 	for(int i=0;i<length;i++)
// 	{

// 	}

// }

void solve(){

	int n;
	cin >>n ;
	string m;
	cin >> m;
	ll sum=0,sum1=0,sum2=0;
	char a=m[0],b=m[1];

	for(int i=0;i<n;i++)
	{
		if(m[i]==m[i+1])
			{
				a = m[i];
				sum++;
				sum%=998244353 ;}
		else
			{
				sum++;break;
	}	}

	sum1 = sum;
	sum = 0;

	for(int i=n-1;i>=0;i--)
	{
		if(m[i]==m[i-1])
			{b = m[i];
				sum++;
				sum%=998244353;}
		else
			{
				sum++;
				;break;
	}	}

	sum2 = sum;

	if(a!=b)
	{
		cout << (sum1+sum2+1)%998244353 <<endl;
	}

	else
	{
		cout << (1+ sum1 + sum2 + sum1*sum2)%998244353 <<endl;
	}

}

int main() {
	// #ifndef opp
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	// cin >> t;

	for(ll i=0;i<t;i++)
	{
		solve();

	}
	return 0;
}


#include <bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include <sstream>

using namespace std;
typedef long long int ll;
#define nl prllf("\n");
#define pp pair<ll,ll>
#define INT_BITS 32
#define ifo(i) (i%2!=0) ? 0 : 1
#define f(i,n) for(int i=0;i<n;i++)
#define fn(i,k,n) for(int i=k;i<n;i++)

// void solve()
// {

// 	int n;
// 	cin >> n;
// 	string m;
// 	cin >> m;
// 	vector<pair<ll,ll> > a(n);
// 	ll x,y;
// 	for(int i=0;i<n;i++)
// 		{	cin >> x;
// 			a[i] = make_pair(x,i+1);
// 		}

// 	sort(a,a+n);
// 	int length = m.length();
// 	for(int i=0;i<length;i++)
// 	{

// 	}

// }

void solve(){

	int n;
	cin >>n ;
	string m;
	cin >> m;
	ll sum=0,sum1=0,sum2=0;
	char a=m[0],b=m[1];

	for(int i=0;i<n;i++)
	{
		if(m[i]==m[i+1])
			{
				a = m[i];
				sum++;
				}
		else
			{
				sum++;
				break;
	}	}

	sum1 = sum;
	sum = 0;

	for(int i=n-1;i>=0;i--)
	{
		if(m[i]==m[i-1])
			{b = m[i];
				sum++;
				}
		else
			{
				sum++;
				;break;
	}	}

	sum2 = sum;

	if(a!=b)
	{
		cout << (sum1+sum2+1) <<endl;
	}

	else
	{
		cout << ((sum1+1)*(sum2+1))%998244353 <<endl;
	}

}

int main() {
	// #ifndef opp
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	// cin >> t;

	for(ll i=0;i<t;i++)
	{
		solve();

	}
	return 0;
}


#include <bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include <sstream>

using namespace std;
typedef long long int ll;
#define nl prllf("\n");
#define pp pair<ll,ll>
#define INT_BITS 32
#define ifo(i) (i%2!=0) ? 0 : 1
#define f(i,n) for(int i=0;i<n;i++)
#define fn(i,k,n) for(int i=k;i<n;i++)

// void solve()
// {

// 	int n;
// 	cin >> n;
// 	string m;
// 	cin >> m;
// 	vector<pair<ll,ll> > a(n);
// 	ll x,y;
// 	for(int i=0;i<n;i++)
// 		{	cin >> x;
// 			a[i] = make_pair(x,i+1);
// 		}

// 	sort(a,a+n);
// 	int length = m.length();
// 	for(int i=0;i<length;i++)
// 	{

// 	}

// }

void solve(){

	int n;
	cin >>n ;
	string m;
	cin >> m;
	ll sum=0,sum1=0,sum2=0;
	char a=m[0],b=m[n-1];

	for(int i=0;i<n;i++)
	{
		if(m[i]==m[i+1])
			{
				a = m[i];
				sum++;
				}
		else
			{
				sum++;
				break;
	}	}

	sum1 = sum;
	sum = 0;

	for(int i=n-1;i>=0;i--)
	{
		if(m[i]==m[i-1])
			{b = m[i];
				sum++;
				}
		else
			{
				sum++;
				;break;
	}	}

	sum2 = sum;

	if(a!=b)
	{
		cout << (sum1+sum2+1) <<endl;
	}

	else
	{
		cout << ((sum1+1)*(sum2+1))%998244353 <<endl;
	}

}

int main() {
	// #ifndef opp
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	// cin >> t;

	for(ll i=0;i<t;i++)
	{
		solve();

	}
	return 0;
}


#include <bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include <sstream>

using namespace std;
typedef long long int ll;
#define nl prllf("\n");
#define pp pair<ll,ll>
#define INT_BITS 32
#define ifo(i) (i%2!=0) ? 0 : 1
#define f(i,n) for(int i=0;i<n;i++)
#define fn(i,k,n) for(int i=k;i<n;i++)

// void solve()
// {

// 	int n;
// 	cin >> n;
// 	string m;
// 	cin >> m;
// 	vector<pair<ll,ll> > a(n);
// 	ll x,y;
// 	for(int i=0;i<n;i++)
// 		{	cin >> x;
// 			a[i] = make_pair(x,i+1);
// 		}

// 	sort(a,a+n);
// 	int length = m.length();
// 	for(int i=0;i<length;i++)
// 	{

// 	}

// }

void solve(){

	int n;
	cin >>n ;
	string m;
	cin >> m;
	ll sum=0,sum1=0,sum2=0;
	char a=m[0],b=m[1];

	for(int i=0;i<n;i++)
	{
		if(m[i]==m[i+1])
			{
				a = m[i];
				sum++;
				sum%=998244353 ;}
		else
			{
				sum++;break;
	}	}

	sum1 = sum;
	sum = 0;

	for(int i=n-1;i>=0;i--)
	{
		if(m[i]==m[i-1])
			{b = m[i];
				sum++;
				sum%=998244353;}
		else
			{
				sum++;
				;break;
	}	}

	sum2 = sum;

	if(a!=b)
	{
		cout << (sum1+sum2+1)%998244353 <<endl;
	}

	else
	{
		cout << (1+ sum1 + sum2 + ((sum1*sum2)%998244353))%998244353 <<endl;
	}

}

int main() {
	// #ifndef opp
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1;
	// cin >> t;

	for(ll i=0;i<t;i++)
	{
		solve();

	}
	return 0;
}


def stringflip(l,s):
    news=""
    for i in range(l):
        if s[l-i-1]=="0":
            news+="1"
        else:
            news+="0"
    if l!=n:
        news+=s[l:]
    return news

def flip(n,a,b):
    if a==b:
        print(0)
        return
    #a to b
    moves=0
    array=[]
    for i in range(n):
        if a[0]==b[n-i-1]:
            array.append(1)

            array.append(n-i)
            moves+=2
            stringflip(1,a)
            a=stringflip(n-i,a)
        else:
            array.append(n-i)
            moves+=1
            a=stringflip(n-i,a)

    print(moves,end=" ")
    for x in array:
        print(x,end=" ")
    print()
    return

t=int(input())
a=[]
for j in range(t):
    n=int(input())
    d=input()
    e=input()
    a.append([n,d,e])
for x in a:
    flip(*x)


import sys

def flip(src, n):
    old_prefix = src[:n]
    for i in range(n):
        src[n-i-1] = 1 - int(old_prefix[i])

def transform(src, target):
    res = []
    for i in range(len(src)):
        if src[i] != target[i]:
            flip(src, i+1)
            res.append(i+1)
            flip(src, 1)
            res.append(1)
            flip(src, i+1)
            res.append(i+1)
    print(len(res), *res)

t = int(sys.stdin.readline().strip())
for i in range (t):
    N = int(sys.stdin.readline().strip())
    a = []
    for i in sys.stdin.readline().strip():
        a.append(i)

    b = []
    for i in sys.stdin.readline().strip():
        b.append(i)
    transform(a,b)


from sys  import stdin,stdout

import bisect

import math

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

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

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

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r

def solve():
    n=inp()
    a=input()
    b=input()
    j=n-1
    x=[]
    if a==b:
        print(0)
        return
    while j>=0:
        if a[j]==b[j]:
            j-=1

        elif a[0]!=b[j]:
            x.append(j+1)
            p=''
            for i  in range(j+1):
                if a[i]=='1':
                    p+='0'
                else:
                    p+='1'
            a=p[::-1]+a[j:]
            j-=1
        else:
            x.append(1)
            if a[0]=='1':
                a='0'+a[1:]
            else:
                a='1'+a[1:]

    print(len(x),*x)

for _ in range(inp()):
    solve()


import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools
from collections import deque,defaultdict,OrderedDict
import collections

def main():
    starttime=datetime.datetime.now()
    if(os.path.exists('input.txt')):
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")

    #Solving Area Starts-->

    #Solving Area Starts-->
    for _ in range(ri()):
        n=ri()
        a=rs()
        b=rs()
        s=""
        if a==b:
            print(0)
            continue
        if n==1:
            print(1,1)
            continue

        ans1=[]
        ans2=[]
        z=0

        c=0
        for j in range(n):
            if a[j]=='0':
                break
            else:
                c+=1
        if c>0:
            ans1.append(c)

        i=c
        while i<n:
            if a[i]=='1':
                if i-1>=0:
                    ans1.append(i)
                    s='1'*(i)
                if a[i:]=='1'*(n-len(s)):
                    z=1
                    break
                for k in range(i,n):
                    if a[k]=='0':
                        break
                ans1.append(k)
                i=k+1
            else:
                i+=1
        if z==1:
            ans1.append(n)

        z=0
        c=0
        for j in range(n):
            if b[j]=='0':
                break
            else:
                c+=1
        if c>0:
            ans2.append(c)
        i=c
        while i<n:
            if b[i]=='1':
                if i-1>=0:
                    ans2.append(i)
                    s='1'*(i)
                if b[i:]=='1'*(n-len(s)):
                    z=1
                    break
                for k in range(i,n):
                    if b[k]=='0':
                        break
                ans2.append(k)
                i=k+1
            else:
                i+=1

        if z==1:
            ans2.append(n)
        # print(ans1)
        # print(ans2)
        print(len(ans1)+len(ans2),*(ans1+ans2[::-1]))

    #<--Solving Area Ends
    endtime=datetime.datetime.now()
    time=(endtime-starttime).total_seconds()*1000
    if(os.path.exists('input.txt')):
        print("Time:",time,"ms")

class FastReader(io.IOBase):
    newlines = 0

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

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

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

class FastWriter(io.IOBase):

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

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

class FastStdin(io.IOBase):
    def __init__(self, fd=0):
        self.buffer = FastReader(fd)
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

class FastStdout(io.IOBase):
    def __init__(self, fd=1):
        self.buffer = FastWriter(fd)
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.flush = self.buffer.flush

if __name__ == '__main__':
    sys.stdin = FastStdin()
    sys.stdout = FastStdout()
    main()


import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
# import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def IF(c, t, f): return t if c else f

def main():
    t = I()

    rr = []
    for _ in range(t):
        n = I()
        a = [int(c) for c in S()]
        b = [int(c) for c in S()]

        r = []
        for i in range(n-1,-1,-1):
            if a[i] == b[i]:
                continue

            if a[0] == b[i]:
                r.append(1)
            r.append(i+1)

            t = [0] * n
            for j in range(i):
                if a[i-j] == 0:
                    t[j] = 1
            a = t

        rr.append(JA([len(r)] + r, " "))

    return JA(rr, "\n")

print(main())


tc=int(input())
for ctr in range(tc):
  n=int(input())
  a=list(input().strip())
  b=list(input().strip())
  k=[]
  for i in range(0,n):
    if a[i]!=b[i]:
      for j in range(0,i+1):
        if a[j]=='0':
          a[j]='1'
        else:
          a[j]='0'
      if a[i]=='0':
          a[i]='1'
      else:
          a[i]='0'
      for j in range(0,i+1):
        if a[j]=='0':
          a[j]='1'
        else:
          a[j]='0'
      k.append(i+1)
  print(len(k),*k)


numberOfTc=int(input())
for ctr in range(1,numberOfTc+1):
  n=int(input())
  a=input()
  b=input()
  l=[]
  for i in range(0,n):
    if a[i]!=b[i]:
      l.append(i+1)
  if len(l)==0:
    print(0)
  else:
    print(len(l),end=" ")
    print(*l)


tc=int(input())
for ctr in range(tc):
  n=int(input())
  a=list(input().strip())
  b=list(input().strip())
  k=[]
  for i in range(0,n):
    if a[i]!=b[i]:
      for j in range(0,i+1):
        if a[j]=='0':
          a[j]='1'
        else:
          a[j]='0'
      if a[i]=='0':
          a[i]='1'
      else:
          a[i]='0'
      for j in range(0,i+1):
        if a[j]=='0':
          a[j]='1'
        else:
          a[j]='0'
      if i>0:
        k.append(i+1)
      k.append(1)
      if i>0:
        k.append(i+1)
  print(len(k),*k)


tc=int(input())
for ctr in range(tc):
  n=int(input())
  a=list(input().strip())
  b=list(input().strip())
  k=[]
  for i in range(0,n):
    if a[i]!=b[i]:
      if i>0:
        k.append(i+1)
      k.append(1)
      if i>0:
        k.append(i+1)
  print(len(k),*k)


def f(x):
    for i in range(int((x+1)/2)):
        A[i],A[x-1-i] = 1-A[x-1-i],1-A[i]

for tc in range(int(input())):
    n = int(input())
    a = input()
    b = input()
    A = []
    steps = []
    for i in a:
        A.append(int(i))
    for i in range(n-1,-1,-1):
        if A[i] != int(b[i]):
            if A[0] == A[i]:
                steps.append(i+1)
                f(i+1)
            else:
                steps.append(1)
                steps.append(i+1)
                f(1)
                f(i+1)
    print(len(steps),end= ' ')
    for i in steps:
        print(i,end=' ')
    print()


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


gets.to_i.times do
    n = gets.to_i
    a, b = gets, gets
    res = []
    (0.. n).each do |i|
        if a[i] != b[i]
            res << i + 1 if i > 0
            res << 1
            res << i + 1 if i > 0
        end
    end
    puts res.size, res.join(' ')
end


from sys import stdin, stdout
def solve():
    n = int(stdin.readline())
    a = stdin.readline().strip()
    b = stdin.readline().strip()
    ans = []
    i = 0
    for x, y in zip(a, b):
        i += 1
        if x != y:
            ans.extend((i, 1, i))
    stdout.write(str(len(ans)))
    stdout.write(''.join(" %d" % x for x in ans))
    stdout.write('\n')
T = int(stdin.readline())
for t in xrange(T):
    solve()


#include <stdio.h>
#include <stdlib.h>

typedef long long int lli;

#define in32(x) scanf("%d", &x)
#define out32(x) printf("%d\n", (x))
#define in64(x) scanf("%lld", &x)
#define out64(x) printf("%lld\n", (x))
#define instr(x) scanf("%s", x)
#define outstr(x) printf("%s\n", (x))
#define fo3(a,b,c) for(a = (b); a <= (c); a++)
#define of3(a,b,c) for(a = (b); a >= (c); a--)

#define MIN(a,b) (((a)<(b))?(a):(b))

void sort(int * arr, int n) {
    int i, j;
    if (n < 12) {
        fo3(i, 0, n - 1) {
            for(j = i - 1; j >= 0 && arr[j] > arr[j + 1]; j--) {
                arr[j] ^= arr[j+1];
                arr[j+1] ^= arr[j];
                arr[j] ^= arr[j+1];
            }
        }
        return;
    }
    int * tmp = malloc(n * sizeof(int));
    int m = (n>>1);
    sort(arr, m);
    sort(arr + m, n - m);
    int fptr = 0, bptr = m;
    for (i = 0; i < n; i++) {
        if (fptr == m || (bptr != n && arr[bptr] < arr[fptr]))
            tmp[i] = arr[bptr++];
        else
            tmp[i] = arr[fptr++];
    }
    for (int i = 0; i < n; i++)
        arr[i] = tmp[i];
    free(tmp);
}

int main() {
    int t;
    int n;
    in32(t);
    while (t--) {
        in32(n);
        char * s1 = calloc(n + 1, sizeof(char));
        char * s2 = calloc(n + 1, sizeof(char));
        instr(s1);
        instr(s2);
        int * moves = calloc(n * 2, sizeof(int));
        int mvs = 0;
        int st = 0;
        int en = n - 1;
        int fwd = 1;
        int e2 = n - 1;

        while (e2 >= 0) {
            if (fwd && s1[en] == s2[e2]) {
                en--;
            } else if (!fwd && s1[st] != s2[e2]) {
                st++;
            } else if (fwd) {
                if (s1[st] == s2[e2])
                    moves[mvs++] = 1;
                moves[mvs++] = e2 + 1;
                st++;
                fwd = 0;
            } else {
                if (s1[en] != s2[e2])
                    moves[mvs++] = 1;
                moves[mvs++] = e2 + 1;
                en--;
                fwd = 1;
            }
            e2--;
        }
        printf("%d", mvs);
        for (int i = 0; i < mvs;i++){
            printf(" %d", moves[i]);
        }
        printf("\n");
        free(moves);
        free(s1);
        free(s2);
    }
    return 0;
}


#include <stdio.h>

void preflip(char inp[], int b, int e) {
    for(;b<=e; b++, e--) {
        char tmp = inp[e];
        if(inp[b]=='0'){
            inp[e] = '1';
        } else {
            inp[e] = '0';
        }
        if( tmp=='0' ) {
            inp[b] ='1';
        } else {
            inp[b] = '0';
        }
    }
}

int main() {
    int t, n;
    int i, j, k, l;
    int len;
    char sa[1000];
    char sb[1000];

    scanf("%d", &t);
    for(i=0; i<t; i++) {
        int num_ops = 0;
        int ops[3000];
        scanf("%d", &len);
        scanf("%s",sa);
        scanf("%s",sb);
        /*
        printf("Before :");
        for(l=0; l<len; l++) {
            printf(" %c", sa[l]);
        }
        printf("\n");*/

        for(j=len-1; j>=0; j--) {
            if( sa[j] != sb[j] ) {
                if( sa[j] == sa[0] ) {
                    preflip(sa,0,j);
                    ops[num_ops] = j+1;
                    num_ops++;
                    /*
                    printf("after a flip:");
                    for(l=0; l<len; l++) {
                        printf(" %c", sa[l]);
                    }
                    printf("\n");*/

                } else {
                    for(k=j-1; k>=0 && sa[j]==sa[k]; k--);
                    if( k>=0 ) {
                        preflip(sa, 0, k);
                        /*
                        printf("after a flip:");
                        for(l=0; l<len; l++) {
                            printf(" %c", sa[l]);
                        }
                        printf("\n");*/
                        preflip(sa, 0, j);
                        ops[num_ops] = k+1;
                        num_ops++;
                        ops[num_ops] = j+1;
                        num_ops++;
                        /*
                        printf("after a flip:");
                        for(l=0; l<len; l++) {
                            printf(" %c", sa[l]);
                        }
                        printf("\n");*/

                    }
                }
            }
        }
        printf("%d ",num_ops);
        for(j=0; j<num_ops; j++) {
            printf("%d ", ops[j]);
        }
        printf("\n");
    }

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

void perform(char *a , int i )
{
    int j;
    char temp;
    for(j=0 ; j<=i ; j++)
    {
        if(a[j]=='0') a[j]='1';
        else a[j]='0';
    }

    for(j=0 ; j<=i/2 ; j++)
    {
        temp=a[j];
        a[j]=a[i-j];
        a[i-j]=temp;
    }
}

int main()
{
    int T ;
    scanf("%d",&T);
    while(T>0)
    {
        int n , i ;
        scanf("%d",&n);
        char a[n+1] , b[n+1] ;
        scanf("%s%s",a,b);
        a[n] = '\0' ; b[n] = '\0' ;
        int op[3*n];
        int j=0;

        for(i=n-1 ; i>=0 ; i-- )
        {
            if(a[i]!=b[i])
            {
                if(a[0]!=b[i])
                {
                    perform(a , i );
                    op[j]=i+1;
                    j++;
                }
                else {
                        perform(a , 0 );
                        perform(a , i );
                        op[j]=1;
                        j++;
                        op[j]=i+1;
                        j++;
                     }
            }
        }

        printf("%d ",j);
        for(i=0 ; i<j ; i++ )
        {
            printf("%d ",op[i]);
        }
        printf("\n");

        T--;
    }

    return 0;
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using static System.Array;
using static System.Console;
using static System.Math;

namespace Olymp
{
  public class ProblemSolver
  {
    private readonly Tokenizer input;

    private void Swap(char[] a, int n)
    {
      var l = 0;
      var r = n - 1;
      while (l < r)
      {
        Swap(a, l, r);
        l++;
        r--;
      }
    }

    private void Xor(char[] a, int n)
    {
      for (int i = 0; i < n; i++)
        a[i] = a[i] == '0' ? '1' : '0';
    }

    private void Swap(char[] a, int i, int j)
    {
      var t = a[i];
      a[i] = a[j];
      a[j] = t;
    }

    public void Solve()
    {
      var t = input.ReadInt();
      var ans = new List<string>(t);
      for (int _ = 0; _ < t; _++)
      {
        var n = input.ReadInt();
        var a = input.ReadToken().ToCharArray();
        var b = input.ReadToken().ToCharArray();
        var i = n - 1;
        var p = new List<int>();
        while (i >= 0)
        {
          if (a[i] == b[i])
          {
            i--;
            continue;
          }
          if (a[0] == a[i])
          {
            p.Add(i + 1);
            Xor(a, i + 1);
            Swap(a, i + 1);
            i--;
            continue;
          }
          p.Add(1);
          Xor(a, 1);
        }
        ans.Add($"{p.Count} {string.Join(" ", p)}");
      }
      WriteLine(string.Join(Environment.NewLine, ans));
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private readonly TextReader reader;

    public string ReadToEnd() => reader.ReadToEnd();

    public int ReadInt()
    {
      var c = SkipWs();
      if (c == -1)
        throw new EndOfStreamException();
      var isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = reader.Read();
        if (c == -1)
          throw new EndOfStreamException("Digit expected, but end of stream occurs");
      }

      if (!char.IsDigit((char)c))
        throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");

      checked
      {
        var result = (char)c - '0';
        c = reader.Read();
        while (c > 0 && !char.IsWhiteSpace((char)c))
        {
          if (!char.IsDigit((char)c))
            throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");
          result = result * 10 + (char)c - '0';
          c = reader.Read();
        }

        if (isNegative)
          result = -result;
        return result;
      }
    }

    public string ReadLine() => reader.ReadLine();

    public long ReadLong() => long.Parse(ReadToken());

    public double ReadDouble() => double.Parse(ReadToken(), CultureInfo.InvariantCulture);

    public int[] ReadIntArray(int n)
    {
      var a = new int[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public (int, int) Read2Int() => (ReadInt(), ReadInt());

    public (int, int, int) Read3Int() => (ReadInt(), ReadInt(), ReadInt());

    public (int, int, int, int) Read4Int() => (ReadInt(), ReadInt(), ReadInt(), ReadInt());

    public (long, long) Read2Long() => (ReadLong(), ReadLong());

    public long[] ReadLongArray(int n)
    {
      var a = new long[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      var a = new double[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWs();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = reader.Read();
      }

      return sb.ToString();
    }

    private int SkipWs()
    {
      var c = reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  internal class Program
  {
    public static void Main()
    {
      var solver = new ProblemSolver(In);
      solver.Solve();
    }
  }

  #endregion
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using static System.Array;
using static System.Console;
using static System.Math;

namespace Olymp
{
  public class ProblemSolver
  {
    private readonly Tokenizer input;

    public void Solve()
    {
      var t = input.ReadInt();
      var ans = new List<string>(t);
      for (int _ = 0; _ < t; _++)
      {
        var n = input.ReadInt();
        var a = input.ReadToken();
        var b = input.ReadToken();
        var p = new List<int>();
        for (int i = 0; i < n - 1; i++)
        {
          if (a[i] != a[i + 1])
            p.Add(i + 1);
        }
        if (a[n - 1] == '1')
          p.Add(n);
        var c = '0';
        for (int i = n - 1; i >= 0; i--)
        {
          if (b[i] != c)
          {
            p.Add(i + 1);
            c = c == '0' ? '1' : '0';
          }
        }
        p.Insert(0, p.Count);
        ans.Add(string.Join(" ", p));
      }
      WriteLine(string.Join(Environment.NewLine, ans));
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private readonly TextReader reader;

    public string ReadToEnd() => reader.ReadToEnd();

    public int ReadInt()
    {
      var c = SkipWs();
      if (c == -1)
        throw new EndOfStreamException();
      var isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = reader.Read();
        if (c == -1)
          throw new EndOfStreamException("Digit expected, but end of stream occurs");
      }

      if (!char.IsDigit((char)c))
        throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");

      checked
      {
        var result = (char)c - '0';
        c = reader.Read();
        while (c > 0 && !char.IsWhiteSpace((char)c))
        {
          if (!char.IsDigit((char)c))
            throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");
          result = result * 10 + (char)c - '0';
          c = reader.Read();
        }

        if (isNegative)
          result = -result;
        return result;
      }
    }

    public string ReadLine() => reader.ReadLine();

    public long ReadLong() => long.Parse(ReadToken());

    public double ReadDouble() => double.Parse(ReadToken(), CultureInfo.InvariantCulture);

    public int[] ReadIntArray(int n)
    {
      var a = new int[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public (int, int) Read2Int() => (ReadInt(), ReadInt());

    public (int, int, int) Read3Int() => (ReadInt(), ReadInt(), ReadInt());

    public (int, int, int, int) Read4Int() => (ReadInt(), ReadInt(), ReadInt(), ReadInt());

    public (long, long) Read2Long() => (ReadLong(), ReadLong());

    public long[] ReadLongArray(int n)
    {
      var a = new long[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      var a = new double[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWs();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = reader.Read();
      }

      return sb.ToString();
    }

    private int SkipWs()
    {
      var c = reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  internal class Program
  {
    public static void Main()
    {
      var solver = new ProblemSolver(In);
      solver.Solve();
    }
  }

  #endregion
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using static System.Array;
using static System.Console;
using static System.Math;

namespace Olymp
{
  public class ProblemSolver
  {
    private readonly Tokenizer input;

    private void Swap(char[] a, int n)
    {
      var l = 0;
      var r = n - 1;
      while (l < r)
      {
        Swap(a, l, r);
        l++;
        r--;
      }
    }

    private void Xor(char[] a, int n)
    {
      for (int i = 0; i < n; i++)
        a[i] = a[i] == '0' ? '1' : '0';
    }

    private void Swap(char[] a, int i, int j)
    {
      var t = a[i];
      a[i] = a[j];
      a[j] = t;
    }

    public void Solve()
    {
      var t = input.ReadInt();
      var ans = new List<string>(t);
      for (int _ = 0; _ < t; _++)
      {
        var n = input.ReadInt();
        var a = input.ReadToken().ToCharArray();
        var b = input.ReadToken().ToCharArray();
        var p = new List<int>();
        for (int i = n - 1; i >= 0; i--)
        {
          if (a[i] == b[i])
            continue;
          p.Add(i + 1);
          p.Add(1);
          p.Add(i + 1);
        }
        ans.Add($"{p.Count} {string.Join(" ", p)}");
      }
      WriteLine(string.Join(Environment.NewLine, ans));
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private readonly TextReader reader;

    public string ReadToEnd() => reader.ReadToEnd();

    public int ReadInt()
    {
      var c = SkipWs();
      if (c == -1)
        throw new EndOfStreamException();
      var isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = reader.Read();
        if (c == -1)
          throw new EndOfStreamException("Digit expected, but end of stream occurs");
      }

      if (!char.IsDigit((char)c))
        throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");

      checked
      {
        var result = (char)c - '0';
        c = reader.Read();
        while (c > 0 && !char.IsWhiteSpace((char)c))
        {
          if (!char.IsDigit((char)c))
            throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");
          result = result * 10 + (char)c - '0';
          c = reader.Read();
        }

        if (isNegative)
          result = -result;
        return result;
      }
    }

    public string ReadLine() => reader.ReadLine();

    public long ReadLong() => long.Parse(ReadToken());

    public double ReadDouble() => double.Parse(ReadToken(), CultureInfo.InvariantCulture);

    public int[] ReadIntArray(int n)
    {
      var a = new int[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public (int, int) Read2Int() => (ReadInt(), ReadInt());

    public (int, int, int) Read3Int() => (ReadInt(), ReadInt(), ReadInt());

    public (int, int, int, int) Read4Int() => (ReadInt(), ReadInt(), ReadInt(), ReadInt());

    public (long, long) Read2Long() => (ReadLong(), ReadLong());

    public long[] ReadLongArray(int n)
    {
      var a = new long[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      var a = new double[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWs();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = reader.Read();
      }

      return sb.ToString();
    }

    private int SkipWs()
    {
      var c = reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  internal class Program
  {
    public static void Main()
    {
      var solver = new ProblemSolver(In);
      solver.Solve();
    }
  }

  #endregion
}


using System;
using System.Collections.Generic;
using System.IO;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();

        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false});
        int t = sc.NextInt();
        for (int i = 0; i < t; i++)
        {
            Q(sc);
        }

        Console.Out.Flush();
    }

    void Q(Scanner sc)
    {
        int n = sc.NextInt();
        string a = sc.Next();
        string b = sc.Next();

        var ls = new List<int>();
        bool f = false;
        for (int i = n - 1; i >= 0; i--)
        {
            if ((a[i] != b[i]) ^ f)
            {
                ls.Add(i + 1);
                f ^= true;
            }
        }

        Console.WriteLine($"{ls.Count} {string.Join(" ", ls)}");
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();

        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false});
        int t = sc.NextInt();
        for (int i = 0; i < t; i++)
        {
            Q(sc);
        }

        Console.Out.Flush();
    }

    void Q(Scanner sc)
    {
        int n = sc.NextInt();
        string a = sc.Next();
        string b = sc.Next();

        var ls = new List<int>();
        for (int i = 0; i < n; i++)
        {
            if (a[i] != b[i])
            {
                if (i == 0)
                {
                    ls.Add(i + 1);
                }
                else
                {
                    ls.Add(i + 1);
                    ls.Add(1);
                    ls.Add(i + 1);
                }
            }
        }

        Console.WriteLine($"{ls.Count} {string.Join(" ", ls)}");
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int t = int.Parse(Console.ReadLine());
        for (int i = 0; i < t; i++)
        {
            Solve();
        }
    }

    static void Solve()
    {
        int n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine().ToArray();
        var t = Console.ReadLine().ToArray();
        //var d = s.ToArray();
        int begin = 0;
        int end = n - 1;
        bool reversed = false;
        List<int> query = new List<int>();
        for (int i = n - 1; i >= 0; i--)
        {
            if ((s[end] != t[i]) ^ reversed)
            {
                if ((s[begin] == t[i]) ^ reversed)
                {
                    query.Add(1);
                    //Array.Reverse(d, 0, 1);
                    //d = d.Select((_, ind) => (char)(ind < 1 ? _ ^ '0' ^ '1' : _)).ToArray();
                }
                query.Add(i + 1);
                //Array.Reverse(d, 0, i + 1);
                //d = d.Select((_, ind) => (char)(ind <= i ? _ ^ '0' ^ '1' : _)).ToArray();
                var tmp = begin;
                begin = end;
                end = tmp;
                reversed = !reversed;
            }
            end += reversed ? 1 : -1;
           // Console.WriteLine($"{string.Join("", d)} {begin} {end} {reversed}");
        }

        //Console.WriteLine(string.Join("", d));
        if (query.Count == 0) Console.WriteLine(query.Count);
        else Console.WriteLine($"{query.Count} {string.Join(" ", query)}");
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Flip
{
    class Program
    {
        static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine().Trim());
            for (int i = 0; i < t; i++)
            {
                int n = int.Parse(Console.ReadLine().Trim());
                int[] start = change(Console.ReadLine().Trim());

                int[] finish = change(Console.ReadLine().Trim());
                Console.WriteLine(flip(start, finish, n));
            }
            //Console.ReadKey();
        }
        static string flip(int[] start, int[] finish, int n)
        {
            /*
            Console.WriteLine("n = " + n);
            Console.Write("Start: ");
            print_array(start);
            Console.Write("Finish: ");
            print_array(finish);
            */
            List<int> result = new List<int>();
            for (int i = n - 1; i >= 0; i--)
            {
                //print_array(start);
                //Console.WriteLine(finish.Length);
                //Console.WriteLine(i);
                if (start[i] == finish[i])
                {
                    //Console.WriteLine("This can't happen");
                    continue;
                }
                if (start[i] == start[0])
                {
                    //Console.WriteLine("This must happen");
                    mainflip(i, ref start);
                    result.Add(i + 1);
                }
                else
                {
                    result.Add(1);
                    result.Add(i + 1);

                    mainflip(0, ref start);
                    mainflip(i, ref start);
                }
            }
            string answer = "";

            int[] final_result = result.ToArray();
            final_result.Reverse();
            answer += final_result.Length.ToString() + " ";
            foreach (int i in final_result)
            {
                answer += i.ToString() + " ";
            }
            return answer;
        }

        static void mainflip(int n, ref int[] number)
        {
            for (int i = 0; i <= n; i++)
            {
                number[i] = (number[i] + 1) % 2;
            }
            for (int i = 0; i <= n / 2; i++)
            {
                int t = number[n - i];
                number[n - i] = number[i];
                number[i] = t;
            }
        }

        static int[] change(string number)
        {
            List<int> result = new List<int>();
            foreach (char i in number)
            {
                result.Add(i - '0');
            }
            return result.ToArray();
        }
        static void print_array(int[] input)
        {
            foreach (int g in input)
            {
                Console.Write(" {0}", g);
            }
            Console.WriteLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;

// (づ°ω°)づﾐe★゜・。。・゜゜・。。・゜☆゜・。。・゜゜・。。・゜
public class Solver
{
    public void Solve()
    {
        for (int tt = ReadInt(); tt > 0; tt--)
        {
            int n = ReadInt();
            var a = ReadToken();
            var b = ReadToken();

            var ans = new List<int>();
            bool rev = false;
            int l = 0, r = n - 1;
            for (int i = n - 1; i >= 0; i--)
            {
                int x = rev ? l : r;
                char v = a[x];
                if (rev)
                    v = v == '0' ? '1' : '0';
                if (v != b[i])
                {
                    int first = rev ? r : l;
                    char vfirst = a[first];
                    if (rev)
                        vfirst = vfirst == '0' ? '1' : '0';
                    if (vfirst == b[i])
                    {
                        ans.Add(1);
                    }
                    ans.Add(i + 1);
                    rev = !rev;
                }
                if (rev)
                    l++;
                else
                    r--;
            }

            writer.Write(ans.Count + " ");
            WriteArray(ans);
        }
    }

    #region Main

    protected static TextReader reader;
    protected static TextWriter writer;
    static void Main()
    {
#if DEBUG
        reader = new StreamReader("..\\..\\input.txt");
        //reader = new StreamReader(Console.OpenStandardInput());
        writer = Console.Out;
        //writer = new StreamWriter("..\\..\\output.txt");
#else
        reader = new StreamReader(Console.OpenStandardInput());
        writer = new StreamWriter(Console.OpenStandardOutput());
        //reader = new StreamReader("input.txt");
        //writer = new StreamWriter("output.txt");
#endif
        try
        {
            new Solver().Solve();
            //var thread = new Thread(new Solver().Solve, 1024 * 1024 * 128);
            //thread.Start();
            //thread.Join();
        }
        catch (Exception ex)
        {
#if DEBUG
            Console.WriteLine(ex);
#else
            throw;
#endif
        }
        reader.Close();
        writer.Close();
    }

    #endregion

    #region Read / Write
    private static Queue<string> currentLineTokens = new Queue<string>();
    private static string[] ReadAndSplitLine() { return reader.ReadLine().Split(new[] { ' ', '\t', }, StringSplitOptions.RemoveEmptyEntries); }
    public static string ReadToken() { while (currentLineTokens.Count == 0) currentLineTokens = new Queue<string>(ReadAndSplitLine()); return currentLineTokens.Dequeue(); }
    public static int ReadInt() { return int.Parse(ReadToken()); }
    public static long ReadLong() { return long.Parse(ReadToken()); }
    public static double ReadDouble() { return double.Parse(ReadToken(), CultureInfo.InvariantCulture); }
    public static int[] ReadIntArray() { return ReadAndSplitLine().Select(int.Parse).ToArray(); }
    public static long[] ReadLongArray() { return ReadAndSplitLine().Select(long.Parse).ToArray(); }
    public static double[] ReadDoubleArray() { return ReadAndSplitLine().Select(s => double.Parse(s, CultureInfo.InvariantCulture)).ToArray(); }
    public static int[][] ReadIntMatrix(int numberOfRows) { int[][] matrix = new int[numberOfRows][]; for (int i = 0; i < numberOfRows; i++) matrix[i] = ReadIntArray(); return matrix; }
    public static int[][] ReadAndTransposeIntMatrix(int numberOfRows)
    {
        int[][] matrix = ReadIntMatrix(numberOfRows); int[][] ret = new int[matrix[0].Length][];
        for (int i = 0; i < ret.Length; i++) { ret[i] = new int[numberOfRows]; for (int j = 0; j < numberOfRows; j++) ret[i][j] = matrix[j][i]; }
        return ret;
    }
    public static string[] ReadLines(int quantity) { string[] lines = new string[quantity]; for (int i = 0; i < quantity; i++) lines[i] = reader.ReadLine().Trim(); return lines; }
    public static void WriteArray<T>(IEnumerable<T> array) { writer.WriteLine(string.Join(" ", array)); }
    public static void Write(params object[] array) { WriteArray(array); }
    public static void WriteLines<T>(IEnumerable<T> array) { foreach (var a in array) writer.WriteLine(a); }
    private class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        public new TValue this[TKey key]
        {
            get { return ContainsKey(key) ? base[key] : default(TValue); }
            set { base[key] = value; }
        }
    }
    private static T[] Init<T>(int size) where T : new() { var ret = new T[size]; for (int i = 0; i < size; i++) ret[i] = new T(); return ret; }
    #endregion
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Text;
using System.Linq;

using E = System.Linq.Enumerable;

internal partial class Solver {
    public void Run() {
        int t = ni();
        while (t-- > 0) {
            var n = ni();
            var a = ns().Select(c => c == '1').ToArray();
            var b = ns().Select(c => c == '1').ToArray();
            var ans = new List<int>();
            for (int i = n - 1; i >= 0; i--) {
                if ((a[i] != b[i])) { // diff
                    if ((a[0] == b[i])) { // same
                        a[0] ^= true;
                        ans.Add(1);
                    }
                    ans.Add(i + 1);
                    Array.Reverse(a, 0, i + 1);
                    for (int j = 0; j <= i; j++) {
                        a[j] ^= true;
                    }
                }
            }
            //a.SequenceEqual(b).Dump();
            cout.WriteLine(new[] { ans.Count }.Concat(ans).JoinToString(" "));
        }
    }
}

// PREWRITEN CODE BEGINS FROM HERE

static public class StringExtensions {
    static public string JoinToString<T>(this IEnumerable<T> source, string separator = " ") {
        return string.Join(separator, source);
    }
}

internal partial class Solver : Scanner {
    public static void Main() {
#if LOCAL
        byte[] inputBuffer = new byte[1000000];
        var inputStream = Console.OpenStandardInput(inputBuffer.Length);
        using (var reader = new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)) {
            Console.SetIn(reader);
            new Solver(Console.In, Console.Out).Run();
        }
#else
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver(Console.In, Console.Out).Run();
        Console.Out.Flush();
#endif
    }

#pragma warning disable IDE0052
    private readonly TextReader cin;
    private readonly TextWriter cout;
    private readonly TextWriter cerr;
#pragma warning restore IDE0052

    public Solver(TextReader reader, TextWriter writer)
        : base(reader) {
        cin = reader;
        cout = writer;
        cerr = Console.Error;
    }

    public Solver(string input, TextWriter writer)
        : this(new StringReader(input), writer) {
    }

#pragma warning disable IDE1006
#pragma warning disable IDE0051
    private int ni() { return NextInt(); }
    private int[] ni(int n) { return NextIntArray(n); }
    private long nl() { return NextLong(); }
    private long[] nl(int n) { return NextLongArray(n); }
    private double nd() { return NextDouble(); }
    private double[] nd(int n) { return NextDoubleArray(n); }
    private string ns() { return Next(); }
    private string[] ns(int n) { return NextArray(n); }
#pragma warning restore IDE1006
#pragma warning restore IDE0051
}

#if DEBUG
internal static class LinqPadExtension {
    public static string TextDump<T>(this T obj) {
        if (obj is IEnumerable) return (obj as IEnumerable).Cast<object>().JoinToString().Dump();
        else return obj.ToString().Dump();
    }
    public static T Dump<T>(this T obj) {
        return LINQPad.Extensions.Dump(obj);
    }
}
#endif

public class Scanner {
    private readonly TextReader Reader;
    private readonly CultureInfo ci = CultureInfo.InvariantCulture;

    private readonly char[] buffer = new char[2 * 1024];
    private int cursor = 0, length = 0;
    private string Token;
    private readonly StringBuilder sb = new StringBuilder(1024);

    public Scanner()
        : this(Console.In) {
    }

    public Scanner(TextReader reader) {
        Reader = reader;
    }

    public int NextInt() { return checked((int)NextLong()); }
    public long NextLong() {
        var s = Next();
        long r = 0;
        int i = 0;
        bool negative = false;
        if (s[i] == '-') {
            negative = true;
            i++;
        }
        for (; i < s.Length; i++) {
            r = r * 10 + (s[i] - '0');
#if DEBUG
            if (!char.IsDigit(s[i])) throw new FormatException();
#endif
        }
        return negative ? -r : r;
    }
    public double NextDouble() { return double.Parse(Next(), ci); }
    public string[] NextArray(int size) {
        string[] array = new string[size];
        for (int i = 0; i < size; i++) {
            array[i] = Next();
        }

        return array;
    }
    public int[] NextIntArray(int size) {
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextInt();
        }

        return array;
    }

    public long[] NextLongArray(int size) {
        long[] array = new long[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextLong();
        }

        return array;
    }

    public double[] NextDoubleArray(int size) {
        double[] array = new double[size];
        for (int i = 0; i < size; i++) {
            array[i] = NextDouble();
        }

        return array;
    }

    public string Next() {
        if (Token == null) {
            if (!StockToken()) {
                throw new Exception();
            }
        }
        var token = Token;
        Token = null;
        return token;
    }

    public bool HasNext() {
        if (Token != null) {
            return true;
        }

        return StockToken();
    }

    private bool StockToken() {
        while (true) {
            sb.Clear();
            while (true) {
                if (cursor >= length) {
                    cursor = 0;
                    if ((length = Reader.Read(buffer, 0, buffer.Length)) <= 0) {
                        break;
                    }
                }
                var c = buffer[cursor++];
                if (33 <= c && c <= 126) {
                    sb.Append(c);
                } else {
                    if (sb.Length > 0) break;
                }
            }

            if (sb.Length > 0) {
                Token = sb.ToString();
                return true;
            }

            return false;
        }
    }
}