#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define mod 998244353

using namespace std;
typedef long long ll;
const int MAXN = 300005;
int n,cnt[3],x[3],y[3];
char str[MAXN];

int main()
{
	cin >> n >> str+1;
	n *= 3;
	ll ans = 1;
	for(int i = 1; i<=n; i++)
	{
		memcpy(x,cnt,sizeof(x)), sort(x,x+3);
		int op = 0;
		if(str[i]=='R')
			op = 0;
		if(str[i]=='G')
			op = 1;
		if(str[i]=='B')
			op = 2;
		cnt[op]++;
		memcpy(y,cnt,sizeof(y)), sort(y,y+3);
		if(x[2]!=y[2])
			;
		else if(x[0]!=y[0])
			ans = ans*(x[1]-x[0])%mod;
		else
			ans = ans*(x[2]-x[1])%mod;
	}
	n /= 3;
	for(int i = 1; i<=n; i++)
		ans = ans*i%mod;
	cout << ans << endl;
	return 0;
}
