#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 998244353
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
 
//ll k,x,y;
 
int main(){
  int n;
  ll ans=1LL;
  cin >> n;
  string s;
  cin>>s;
  
  vi lr(n*3,0);//0がL、1が中間、2がR
  vi rgb(3,0);
  vi dat0(n*3,0);//0が何個つながってるか、1が何こつながってるか記憶するやつ
  vi datn(n*3,0);//0が何個つながってるか、1が何こつながってるか記憶するやつ
 
  ll flag=0;
  REP(i,n*3){
    if (s[i]=='R') flag=0;
    if (s[i]=='G') flag=1;
    if (s[i]=='B') flag=2;
    rgb[flag]++;
    lr[i]=1;
    if ((rgb[(flag+1)%3]!=0)&(rgb[(flag+2)%3]!=0)){
      lr[i]=2;
      rgb[0]--;
      rgb[1]--;
      rgb[2]--;
    }else{
      if (rgb[flag]>rgb[(flag+1)%3]){
        if (rgb[flag]>rgb[(flag+2)%3]){
          lr[i]=0;
        }
      }
    }
  }
 
 
  dat0[0]=(ll)s[0]*1LL;
  datn[0]=1;
  int w=0;
  int ref=0;
  int dref=0;
  for(int i=1;i<n*3;i++){
    if (lr[i]==2){
      ll nnum=0LL;
      for(int j=dref+1;j<=w;j+=2){
          nnum+=datn[j];
      }
      
      ans*=nnum;
      ans%=MOD;
      ans*=datn[dref];
      ans%=MOD;
      datn[dref]--;
      datn[dref+1]--;
 
      if (datn[dref]==0){
        dref+=2;
      }else{
        if (datn[dref+1]==0){
          if (dat0[dref]==dat0[dref+2]){
            datn[dref+2]+=datn[dref];
            dref+=2;
          }else{
            if (dat0[dref+2]==0){
              w--;
              for(int k=i;k>=0;k--){
                if (dat0[dref]==((ll)s[k])){
                  ref=k;
                  break;
                }
              }

            }

          }
          
        }
      }
      continue;
    }else{
      if (lr[ref]==lr[i]){
        datn[w]++;
      }else{
        w++;
        dat0[w]=(ll)s[i]*1LL;
        datn[w]=1;
      }
      ref=i;
    }
  }
 
  REP(i,n){
    ans*=(ll)(i+1LL);
    ans%=MOD;
  }
 
 
  cout<<ans<<endl;
  return 0;
}





/*
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())
#define MOD 998244353 
#define mx 200003
 
string ss;
int n;
 
 
 
int main(){
	cin >> n;
	cin >> ss;
	set<int> R, G, B;
	for(int i = 0; i < n * 3; i++){
		if(ss[i] == 'G')
			G.insert(i);
		else if(ss[i] == 'R')
			R.insert(i);
		else B.insert(i);
	}
	vector<int> tipe(n * 3, -1);
	for(int i = 0; i < n * 3; i++){
		if(tipe[i] != -1)
			continue;
		tipe[i] = 0;
		if(ss[i] == 'R'){
			auto it1 = G.lower_bound(i);
			auto it2 = B.lower_bound(i);
			tipe[min(*it1, *it2)] = 1;
			tipe[max(*it1, *it2)] = 2;
			G.erase(it1);
			B.erase(it2);
		}
		else if(ss[i] == 'G'){
			auto it1 = R.lower_bound(i);
			auto it2 = B.lower_bound(i);
			tipe[min(*it1, *it2)] = 1;
			tipe[max(*it1, *it2)] = 2;
			R.erase(it1);
			B.erase(it2);
		}
		else{
			auto it1 = G.lower_bound(i);
			auto it2 = R.lower_bound(i);
			tipe[min(*it1, *it2)] = 1;
			tipe[max(*it1, *it2)] = 2;
			G.erase(it1);
			R.erase(it2);
		}
	}
	long long nolR = 0, satuR = 0;
	long long nolG = 0, satuG = 0;
	long long nolB = 0, satuB = 0;
	long long jaw = 1;
	for(int i = 0; i < n * 3; i++){
		// debug(i);
		if(tipe[i] == 0){
			if(ss[i] == 'R')
				nolR += 1;
			if(ss[i] == 'G')
				nolG += 1;
			if(ss[i] == 'B')
				nolB += 1;
		}
		else if(tipe[i] == 1){
			if(ss[i] == 'R'){
				// assert((nolG > 0) ^ (nolB > 0));
				if(nolG > 0){
					jaw = jaw * nolG % MOD;
					nolG -= 1;
				}
				else if(nolB > 0){
					jaw = jaw * nolB % MOD;
					nolB -= 1;
				}
				// else assert(false);
				satuR += 1;
			}
			else if(ss[i] == 'G'){
				// assert((nolR > 0) ^ (nolB > 0));
				if(nolR > 0){
					jaw = jaw * (nolR + nolB) % MOD;
					nolR -= 1;
				}
				else if(nolB > 0){
					jaw = jaw * nolB % MOD;
					nolB -= 1;
				}
				// else assert(false);
				satuG += 1;
			}
			else{
				// assert((nolG > 0) ^ (nolR > 0));
				if(nolG > 0){
					jaw = jaw * (nolG + nolR) % MOD;
					nolG -= 1;
				}
				else if(nolR > 0){
					jaw = jaw * nolR % MOD;
					nolR -= 1;
				}
				// else assert(false);
				satuB += 1;
			}
		}
		else{
			if(ss[i] == 'R'){
				// assert((satuG > 0) ^ (satuB > 0));
				if(satuG > 0){
					jaw = jaw * (satuG + satuB) % MOD;
					satuG -= 1;
				}
				else if(satuB > 0){
					jaw = jaw * satuB % MOD;
					satuB -= 1;
				}
				// else assert(false);
			}
			else if(ss[i] == 'G'){
				// assert((satuR > 0) ^ (satuB > 0));
				if(satuR > 0){
					jaw = jaw * (satuR + satuB) % MOD;
					satuR -= 1;
				}
				else if(satuB > 0){
					jaw = jaw * satuB % MOD;
					satuB -= 1;
				}
				// else assert(false);
			}
			else{
				// assert((satuG > 0) ^ (satuR > 0));
				if(satuG > 0){
					jaw = jaw * (satuG + satuR) % MOD;
					satuG -= 1;
				}
				else if(satuR > 0){
					jaw = jaw * satuR % MOD;
					satuR -= 1;
				}
				// else assert(false);
			}
		}
	}
	for(int i = 1; i <= n; i++)
		jaw = jaw * i % MOD;
	cout << jaw << '\n';
  cout<<ss.length()<<endl;
}
*/

Measured memory_bytes: 7684