#include<iostream>
#define mod 998244353
using namespace std;
int n, i, nr, x, sol;
int ok[5];
char s[300005];
int main(){
    cin>> n;
    cin>> s + 1;
    for(i = 1; i <= 3 * n; i++){
        if(s[i] == 'R'){
            s[i] = 1;
        }
        else{
            if(s[i] == 'G'){
                s[i] = 2;
            }
            else{
                s[i] = 3;
            }
        }
    }
    sol = 1;
    for(i = 3 * n; i >= 1; i--){
        if(ok[ s[i] ] > 0){
            sol = sol * 1LL * ok[ s[i] ] % mod;
            ok[ s[i] ]--;
        }
        else{
            if(nr > 0 && x != s[i]){
                ok[6 - s[i] - x]++;
                sol = sol * 1LL * nr % mod;
                nr--;
            }
            else{
                nr++;
                x = s[i];
            }
        }
    }
    for(i = 1; i <= n; i++){
        sol = sol * 1LL * i % mod;
    }
    cout<< sol;
}
