#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
// mint {{{
template <class ModType> struct modint {
    using value_type = typename ModType::value_type;
    using mint = modint<ModType>;
    static value_type mod() { return ModType::value; }

    static value_type inverse(value_type x) {
        value_type y=1,u=mod(),v=0;
        while(x){
            value_type q=u/x;
            u-=q*x; std::swap(x,u);
            v-=q*y; std::swap(y,v);
        }
        assert(x==0 && std::abs(y)==mod() && std::abs(u)==1 && std::abs(v)<mod());
        return v<0?v+mod():v;
    }

    // the member variable
    value_type value;

    // constructors
    modint()=default;
    modint(modint const&)=default;
    modint(modint&&)=default;
    modint& operator=(modint const&)=default;
    modint& operator=(modint&&)=default;
    ~modint()=default;

    template <class T> modint(T t) : value([t] () mutable {
            if ( t <= -static_cast<T>(mod()) || static_cast<T>(mod()) <= t ) t %= mod();
            return t < 0 ? t + mod() : t;
            }()) {}

    // operators
    mint& operator+= (mint y) {
        value += y.value;
        if (mod() <= value) value -= mod();
        return *this;
    }

    mint& operator-= (mint y) {
        value -= y.value;
        if ( value < 0 ) value += mod();
        return *this;
    }

    mint& operator*= (mint y) {
        value = (long long)value * y.value % mod();
        return *this;
    }

    mint& operator/= (mint y) {
        value = (long long)value * inverse(y.value) % mod();
        return *this;
    }

    mint& operator++() { return *this+=1; }
    mint& operator--() { return *this-=1; }
    mint  operator++(int) { mint this_=*this; ++*this; return this_; }
    mint  operator--(int) { mint this_=*this; --*this; return this_; }

    // member functions
    mint& add(mint y) { return *this+=y; }
    mint& sub(mint y) { return *this-=y; }
    mint& mul(mint y) { return *this*=y; }
    mint& div(mint y) { return *this/=y; }
    mint& inv() {
        value = inverse(value);
        return *this;
    }

    mint added(mint y) { mint ans=*this; return ans.add(y); }
    mint subed(mint y) { mint ans=*this; return ans.sub(y); }
    mint muled(mint y) { mint ans=*this; return ans.mul(y); }
    mint dived(mint y) { mint ans=*this; return ans.div(y); }
    mint inved()       { mint ans=*this; return ans.inv(); }

    static mint m1pow(long long y) { return y%2?-1:1; }

    static mint pow(mint x, unsigned long long y) {
        mint ans=1;
        for(;y;y>>=1){
            if(y&1ull) ans*=x;
            x*=x;
        }
        return ans;
    }

    mint& powed(unsigned long long y){
        return *this=pow(*this, y);
    }

    template <class F> mint map(F const& f){
        value=f(value);
        return *this;
    }
};

template <class T> std::ostream& operator<<(std::ostream& os, modint<T> x) { return os << x.value; }

template <class T> modint<T> operator+(modint<T> x, modint<T> y) { return x+=y; }
template <class T> modint<T> operator-(modint<T> x, modint<T> y) { return x-=y; }
template <class T> modint<T> operator*(modint<T> x, modint<T> y) { return x*=y; }
template <class T> modint<T> operator/(modint<T> x, modint<T> y) { return x/=y; }
template <class T> bool operator==(modint<T> x, modint<T> y) { return x.value==y.value; }
template <class T> bool operator!=(modint<T> x, modint<T> y) { return x.value!=y.value; }

template <class T, class U> modint<T> operator+(modint<T> x, U y) { return x+modint<T>(y); }
template <class T, class U> modint<T> operator-(modint<T> x, U y) { return x-modint<T>(y); }
template <class T, class U> modint<T> operator*(modint<T> x, U y) { return x*modint<T>(y); }
template <class T, class U> modint<T> operator/(modint<T> x, U y) { return x/modint<T>(y); }
template <class T, class U> bool operator==(modint<T> x, U y) { return x==modint<T>(y); }
template <class T, class U> bool operator!=(modint<T> x, U y) { return x!=modint<T>(y); }

template <class T, class U> modint<T> operator+(U x, modint<T> y) { return modint<T>(x)+y; }
template <class T, class U> modint<T> operator-(U x, modint<T> y) { return modint<T>(x)-y; }
template <class T, class U> modint<T> operator*(U x, modint<T> y) { return modint<T>(x)*y; }
template <class T, class U> modint<T> operator/(U x, modint<T> y) { return modint<T>(x)/y; }
template <class T, class U> bool operator==(U x, modint<T> y) { return modint<T>(x)==y; }
template <class T, class U> bool operator!=(U x, modint<T> y) { return modint<T>(x)!=y; }

using mod_type = i32;
constexpr mod_type mod = 998244353;
using mint = modint< std::integral_constant<mod_type, mod> >;
//}}}

template <
    usize N, class T, class... Args,
    std::enable_if_t<N==0, int> = 0
 >
auto mkvec(Args... args) {
    return T(args...);
}

template <
    usize N, class T, class... Args,
    std::enable_if_t<N!=0, int> = 0
 >
auto mkvec(usize sz, Args... args) {
    using value_type = std::decay_t<decltype(mkvec<N-1, T>(args...))>;
    return vec<value_type>(sz, value_type(args...));
}

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n, N;
    std::string s;
    std::cin >> n >> s;
    N = 3 * n;

    auto cum = mkvec<2, i32>(N, 3);
    for (usize i=0; i<N; i++) {
        if (i) cum.at(i) = cum.at(i-1);
        cum.at(i).at(s.at(i)%3)++;
    }

    vec<i32> min(N), max(N);
    for (usize i=0; i<N; i++) {
        min.at(i) = *std::min_element(ALL(cum.at(i)));
        max.at(i) = *std::max_element(ALL(cum.at(i)));
    }
    std::adjacent_difference(ALL(min), min.begin());
    std::adjacent_difference(ALL(max), max.begin());

    vec<i32> ear(N, 1);
    for (usize i=0; i<N; i++) {
        if (min.at(i)) ear.at(i) = 2;
        if (max.at(i)) ear.at(i) = 0;
    }

    mint ans = 1;
    vec<usize> now(3);
    for (i32 x: ear) {
        if (x==0) {
            now.at(0)++;
        }
        if (x==1) {
            ans *= now.at(0)--;
            now.at(1)++;
        }
        if (x==2) {
            ans *= now.at(1)--;
            now.at(2)++;
        }
    }

    for (usize i=1; i<=n; i++) {
        ans *= i;
    }
    std::cout << ans << '\n';
}


Measured memory_bytes: 20500