#include<cstdio>
int n,i,j,b[3],a=1,P=998244353;
char c;
int main(){
	scanf("%d\n",&n);
	for(i=1;i<=n;++i)a=1ll*a*i%P;
	for(i=1;i<=3*n;++i){
		c=getchar();
		int &t=b[(c>'B')+(c>'G')],m=1e7;
		for(j=0;j<3;++j)if(b[j]>t&&b[j]-t<m)m=b[j]-t;
		if(m<=n)a=1ll*a*m%P;
		++t;
	}
	printf("%d\n",a);
	return 0;
}