///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=998244353;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

#define R 1
#define G 2
#define B 3
#define RG 4
#define RB 5
#define GB 6
#define RGB 7
int box[10];
 main()

{
    fast
    int n;
    cin>>n;
    string s;
    cin>>s;
    int sz=s.size();
    int ses=1;
    f(i,0,sz-1)
    {
        char ch=s[i];
        if(s[i]=='R')
        {

             if(box[GB]>=1)
             {
                 ses=gun(ses,box[GB]);
                 box[RGB]++;
                 box[GB]--;
             }
             else if(box[G]>=1)
             {
                 ses=gun(ses,box[G]);
                 box[RG]++;
                 box[G]--;
             }
             else if(box[B]>=1)
             {
                 ses=gun(ses,box[B]);
                 box[RB]++;
                 box[B]--;
             }
             else
             {
                 box[R]++;
             }


        }
        else if(s[i]=='G')
        {
            if(box[RB]>=1)
             {
                 ses=gun(ses,box[RB]);
                 box[RGB]++;
                 box[RB]--;
             }
             else if(box[R]>=1)
             {
                 ses=gun(ses,box[R]);
                 box[RG]++;
                 box[R]--;
             }
             else if(box[B]>=1)
             {
                 ses=gun(ses,box[B]);
                 box[GB]++;
                 box[B]--;
             }
             else
             {
                 box[G]++;
             }
        }
        else if(s[i]=='B')
        {
             if(box[RG]>=1)
             {
                 ses=gun(ses,box[RG]);
                 box[RGB]++;
                 box[RG]--;
             }
             else if(box[G]>=1)
             {
                 ses=gun(ses,box[G]);
                 box[GB]++;
                 box[G]--;
             }
             else if(box[R]>=1)
             {
                 ses=gun(ses,box[R]);
                 box[RB]++;
                 box[R]--;
             }
             else
             {
                 box[B]++;
             }
        }
    }
    f(i,1,n)ses=gun(ses,i);
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 3868