/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    ll a;
    const ll MOD=998244353;
    modint(ll a_=0){
        a=((a_%MOD)+MOD)%MOD;
    }
    modint inv()const{
        ll n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y(n);
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y(a+x.a);
        return y;
    }
    modint operator-(const modint& x){
        modint y(a-x.a);
        return y;
    }
    modint operator*(const modint& x){
        modint y(a*x.a);
        return y;
    }
    modint operator/(const modint& x){
        return *this * x.inv();
    }
    modint& operator+=(const modint& x){
        *this=*this+x;
        return *this;
    }
    modint& operator-=(const modint& x){
        *this=*this-x;
        return *this;
    }
    modint& operator*=(const modint& x){
        *this=*this*x;
        return *this;
    }
    modint& operator/=(const modint& x){
        *this=*this/x;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    ll a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(ll a,ll b){
    modint n(1),A(a);
    while(b){
        if(b&1) n*=A;
        A*=A;
        b>>=1;
    }
    return n;
}

class BRGBBalls {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n;
        in>>n;
        string S;
        in>>S;
        vector<int> v(3*n);
        fr(i,3*n){
            if(S[i]=='G') v[i]=1;
            if(S[i]=='B') v[i]=2;
        }
        int a=0,b=0;
        vector<int> p(3),q(3);
        vector<bool> s(3*n),t(3*n);
        fr(i,3*n){
            //cout<<p[0]<<" "<<p[1]<<" "<<p[2]<<" "<<q[0]<<" "<<q[1]<<" "<<q[2]<<endl;
            if(q[v[i]]){
                t[i]=true;
                --q[v[i]];
            }
            else if(p[v[i]]){
                s[i]=true;
                ++p[v[i]];
            }
            else if(p[0]+p[1]+p[2]){
                int j;
                fr(k,3) if(p[k]) j=k;
                --p[j];
                ++q[3-j-v[i]];
            }
            else{
                s[i]=true;
                ++p[v[i]];
            }
        }
        modint ans(1);
        Fr(i,n) ans*=i;
        a=0;b=0;
        fr(i,3*n){
            if(s[i]) ++a;
            else if(t[i]) ans*=b,--b;
            else ans*=a,--a,++b;
        }
        out<<ans<<endl;
    }
};

int main() {
    BRGBBalls solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 1812